Beispiel #1
0
        public void RunUntil(Func <bool> predicate, TimeSpan timeout)
        {
            var cancellationTokenSource = new CancellationTokenSource(timeout);

            while (!cancellationTokenSource.Token.IsCancellationRequested)
            {
                if (predicate())
                {
                    break;
                }

                // TODO: Don't busy wait.
                IJob job;
                if (_jobQueue.Pop(out job))
                {
                    _jobExecutor.Execute(job);
                }
            }

            if (cancellationTokenSource.Token.IsCancellationRequested)
            {
                throw CreateTimeoutException(timeout);
            }
        }