本文整理汇总了TypeScript中@jonggrang/ref.modifyRef_函数的典型用法代码示例。如果您正苦于以下问题:TypeScript modifyRef_函数的具体用法?TypeScript modifyRef_怎么用?TypeScript modifyRef_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了modifyRef_函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: 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
示例2: insert
insert(sess: SS.Session) {
return RV.modifyRef_(this.sessions, oldMap => {
if (sess.id in oldMap) return [oldMap, T.raise(new SS.SessionAlreadyExists(oldMap[sess.id], sess))];
return [SO.insert(sess.id, sess, oldMap), T.pure(void 0)];
})
.chain(identity)
.chain(() => this.addMockOperation({ tag: 'insert', session: sess }));
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:9,代码来源:utils.ts
示例3:
function stopReaper<W>(
s: R.Ref<State<W>>,
empty: W
): T.Task<W> {
return R.modifyRef_(s, mx =>
mx.tag === StateType.NOREAPER
? [{ tag: StateType.NOREAPER } as State<W>, empty ]
: [{ tag: StateType.WORKLOAD, workload: empty } as State<W>, mx.workload ]
);
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:10,代码来源:reaper.ts
示例4: return
return (item: I) => {
function cons(s: State<W>): [State<W>, T.Task<void>] {
let wl: W;
if (s.tag === StateType.NOREAPER) {
wl = settings.cons(item, settings.empty);
return [{ tag: StateType.WORKLOAD, workload: wl }, spawn(settings, stateRef, tidRef)];
}
wl = settings.cons(item, s.workload);
return [{ tag: StateType.WORKLOAD, workload: wl }, T.pure(void 0)];
}
return R.modifyRef_(stateRef, cons)
.chain(identity);
};
开发者ID:syaiful6,项目名称:jonggrang,代码行数:13,代码来源: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: push
.chain(machine => {
function push(i: I): T.Task<void> {
return R.modifyRef(queue, ys => {
let xs = ys.slice();
xs.push(i);
return xs;
});
}
const run: T.Task<void> =
R.modifyRef_(machine, x => [void 0, x]).chain(i => traverse_(loop, i));
function loop(mc: Loop<I>): T.Task<void> {
return R.readRef(queue)
.chain(q => {
if (q.length > 0) {
let head = q[0],
tail = q.slice(1);
return R.writeRef(queue, tail)
.chain(() => mc.loop(head).chain(loop));
}
return mc.tick()
.chain(st => {
return R.readRef(queue)
.chain(q2 => {
if (q2.length === 0) {
return R.writeRef(machine, st)
.then(R.writeRef(queue, []));
}
return loop(st);
});
});
});
}
const inst: EvInstance<I> = { run, push };
return proc(inst)
.chain(step => {
return R.writeRef(machine, step).then(T.pure(inst));
});
});
开发者ID:syaiful6,项目名称:jonggrang,代码行数:38,代码来源:event-queue.ts
示例7: getMockOperation
export function getMockOperation(storage: MockStorage): Promise<L.List<MockOperation>> {
return T.toPromise(RV.modifyRef_(storage.operations, xs => [L.nil, L.reverse(xs)]));
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:3,代码来源:utils.ts
示例8: check
.chain(merge => R.modifyRef_(stateRef, s => check(merge, s)))
开发者ID:syaiful6,项目名称:jonggrang,代码行数:1,代码来源:reaper.ts
注:本文中的@jonggrang/ref.modifyRef_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论