本文整理汇总了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)),