public async Task <ActionResult> Created(Guid id)
        {
            // Commands are processed by a worker role.  It could take time before the read model
            // is in sync.  This polls the database every quarter second to see if the account has been
            // created.  Once it has (or once it times out) the method continues.

            // For the sake of the example, there's no database.  Instead, the model will simply simulate
            // latency to show how polling works.
            var pollInterval = TimeSpan.FromSeconds(0.25);
            var timeout      = TimeSpan.FromSeconds(3);

            var account = await AwaitTimer.WaitUntil(() => GetNewlyCreatedBankAccount(id),
                                                     BankAccountIsValid, pollInterval, timeout);

            return(View(account));
        }
Beispiel #2
0
        /// <summary>
        /// 지정된 시간만큼 대기하는 Task를 생성한다.
        /// </summary>
        /// <param name="time">대기할 시간 (밀리초)</param>
        /// <returns>지정된 시간 후 완료되는 Task</returns>
        public Task Yield(long time)
        {
            var timer = new AwaitTimer();
            timer.interval = time;
            timer.count = 1;
            timer.start = Environment.TickCount;
            pendingTimers.Enqueue(timer);

            return timer.task;
        }