本文整理汇总了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);
});
示例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);
});
示例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')
)
);
});
示例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);
}
示例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);
}));
示例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));
});
示例7:
yield T.forkTask(T.forever(T.co(function* () {
yield AV.takeAVar(baton);
yield T.apathize(settings.action);
return T.delay(settings.frequency);
})));
示例8:
.chain(() => T.delay(10).chain(() => AV.takeAVar(av)));