本文整理匯總了TypeScript中@jonggrang/avar.newEmptyAVar類的典型用法代碼示例。如果您正苦於以下問題:TypeScript newEmptyAVar類的具體用法?TypeScript newEmptyAVar怎麽用?TypeScript newEmptyAVar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了newEmptyAVar類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
export function fork<A>(t: T.Task<A>): T.Task<Forked<A>> {
return AV.newEmptyAVar.chain(avar =>
T.forkTask(T.ensure(t, AV.putAVar(avar, void 0))).chain(fib =>
T.delay(10).map(() => [fib, avar] as [T.Fiber<A>, AV.AVar<void>])
)
);
}
示例2: ChannelItem
export function writeChan<A>(chan: Chan<A>, val: A): T.Task<void> {
return AV.newEmptyAVar
.chain(newHole =>
AV.takeAVar(chan.write)
.chain(oldHole =>
T.apSecond(
AV.putAVar(oldHole, new ChannelItem(val, newHole)),
AV.putAVar(chan.write, newHole)
)
)
);
}
示例3: createQSem
.chain(queue =>
AV.newEmptyAVar.map(head => createQSem(qty, queue, head))
示例4: constructor
readonly write: AV.AVar<ChanStream<A>>
) {
}
}
class ChannelItem<A> {
constructor(readonly head: A, readonly tail: ChanStream<A>) {
}
}
/**
* Creates a new `Chan`nel
*/
export const newChan: T.Task<Chan<any>> = AV.newEmptyAVar
.chain((hole: ChanStream<any>) =>
T.both(AV.newAVar(hole), AV.newAVar(hole))
.map(([read, write]) => new Channel(read, write))
);
/**
* Writes a new value into the `Chan`.
* @param chan
* @param val
*/
export function writeChan<A>(chan: Chan<A>, val: A): T.Task<void> {
return AV.newEmptyAVar
.chain(newHole =>
AV.takeAVar(chan.write)
.chain(oldHole =>
T.apSecond(
AV.putAVar(oldHole, new ChannelItem(val, newHole)),