當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript task.delay函數代碼示例

本文整理匯總了TypeScript中@jonggrang/task.delay函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript delay函數的具體用法?TypeScript delay怎麽用?TypeScript delay使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了delay函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: test

  test('FIFO semantics for the waiters', function* () {
    const qsem: Q.QSem = yield Q.newQSem(0);
    const [t1, m1]: Forked<void> = yield fork(Q.waitQSem(qsem));

    yield stop(t1, m1);
    yield Q.signalQSem(qsem);
    yield T.delay(10);
    const [t2, m2]: Forked<void> = yield fork(Q.waitQSem(qsem));
    yield T.delay(10);

    const result: AV.AVar<boolean> = yield AV.newEmptyAVar;
    const [t3, m3]: Forked<void> = yield fork(
      T.onException(
        Q.waitQSem(qsem),
        AV.putAVar(result, false)
      ).chain(() => AV.putAVar(result, true))
    );
    yield Q.signalQSem(qsem);
    yield T.delay(10);

    yield stop(t2, m2);
    yield stop(t3, m3);

    const r: boolean = yield AV.takeAVar(result);
    assert.ok(r);
    return T.pure(void 0);
  });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:27,代碼來源:qsem.ts

示例2: test

    test('writing unblocks reads', function* () {
      const chan: Q.Chan<number> = yield Q.newChan;
      yield T.forkTask(T.apSecond(T.delay(20), Q.writeChan(chan, 1)));
      const r: P.Either<void, number> = yield compete(T.delay(50), Q.readChan(chan));
      assert.ok(P.isRight(r));

      return T.pure(void 0);
    });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:8,代碼來源:chan.ts

示例3: it

 it('compete should return the fastest task', function () {
   return shouldBe(
     right('right'),
     S.compete(
       T.delay(30).map(() => 'left'),
       T.delay(20).map(() => 'right')
     )
   );
 });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:9,代碼來源:async.ts

示例4: swapWithEmpty

function reaper<W, I>(
  settings: ReaperSettings<W, I>,
  stateRef: R.Ref<State<W>>,
  tidRef: R.Ref<T.Fiber<void> | undefined>
) {
  function swapWithEmpty(s: State<W>): [State<W>, W] {
    if (s.tag === StateType.NOREAPER) {
      throw new Error('unexpected NoReaper (1)');
    }
    return [{ tag: StateType.WORKLOAD, workload: settings.empty }, s.workload ];
  }
  function check(merge: (_: W) => W, s: State<W>): [State<W>, T.Task<void>] {
    if (s.tag === StateType.NOREAPER) {
      throw new Error('unexpected NoReaper (2)');
    }
    let wl = merge(s.workload);
    return settings.isNull(wl)
      ? [{ tag: StateType.NOREAPER }, R.writeRef(tidRef, void 0)]
      : [{ tag: StateType.WORKLOAD, workload: wl }, reaper(settings, stateRef, tidRef) ];
  }
  return T.delay(settings.delay).then(
      R.modifyRef_(stateRef, swapWithEmpty))
    .chain(wl =>
      settings.action(wl))
    .chain(merge => R.modifyRef_(stateRef, s => check(merge, s)))
    .chain(identity);
}
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:27,代碼來源:reaper.ts

示例5: mkAutoUpdate

 return T.toPromise(T.co(function* () {
   const ref: R.Ref<number> = yield R.newRef(0);
   const update: T.Task<number> = R.modifyRef_(ref, i => [i + 1, i + 1]);
   const next: T.Task<number> = yield mkAutoUpdate({ delay: 100, task: update });
   yield T.forIn_(range(1, 11), i => {
     return next.chain(j => {
       assert.equal(i === j && i !== 1, false);
       return T.pure(void 0);
     });
   });
   yield T.delay(300);
   const last1: number = yield R.readRef(ref);
   yield T.delay(200);
   const last2: number = yield R.readRef(ref);
   assert.equal(last1, last2);
   return T.pure(void 0);
 }));
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:17,代碼來源:auto-update.ts

示例6: co

 return co(function* () {
   yield takeAVar(needsRunning);
   const a: A = yield maybe(set.task, identity, applyMaybe(modify, ma)) as Task<A>;
   yield writeRef(currRef, right(a));
   yield putAVar(responseVar, a);
   yield delay(set.delay);
   const responseVar_: AVar<A> = yield newEmptyAVar;
   yield writeRef(currRef, left(responseVar_));
   return loop(responseVar_, just(a));
 });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:10,代碼來源:auto-update.ts

示例7:

 yield T.forkTask(T.forever(T.co(function* () {
   yield AV.takeAVar(baton);
   yield T.apathize(settings.action);
   return T.delay(settings.frequency);
 })));
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:5,代碼來源:debounce.ts

示例8:

 .chain(() => T.delay(10).chain(() => AV.takeAVar(av)));
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:1,代碼來源:utils.ts


注:本文中的@jonggrang/task.delay函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。