本文整理匯總了TypeScript中@jonggrang/task.makeTask函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript makeTask函數的具體用法?TypeScript makeTask怎麽用?TypeScript makeTask使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了makeTask函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: request
return T.toPromise(withApp(app, handler =>
T.makeTask(cb => {
request(handler)
.get('/')
.expect(200)
.expect('hello', cb);
return T.nonCanceler;
})
示例2: waitSignal
function waitSignal(signal: string): T.Task<void> {
return T.makeTask(cb => {
process.once(signal as any, cb as any);
return T.thunkCanceller(() => {
process.removeListener(signal, cb as any);
});
});
}
示例3:
export function writeSock<W extends Writable>(writable: W, buffer: Buffer): T.Task<void> {
return T.makeTask({
writable,
buffer,
handle: handleWriteSock,
cancel: doNothingTask
} as T.Computation<void>);
}
示例4: cleanUpListenerWS
export function pipeStream<W extends Writable, R extends Readable>(ws: W, rs: R, opts?: { end?: boolean }): T.Task<void> {
return T.makeTask(cb => {
rs.pipe(ws, opts);
const doEnd = (!opts || opts.end !== false) && (ws as any) !== process.stdout && (ws as any) !== process.stderr;
const state: PipeState = {
onError: null,
onSuccess: null,
resolved: false
};
if (doEnd) {
state.onError = onErrorWS.bind(null, state, ws, cb);
state.onSuccess = onSuccessWS.bind(null, state, ws, cb);
ws.once('error', state.onError as any);
ws.once('finish', state.onSuccess as any);
return T.thunkCanceller(() => cleanUpListenerWS(state, ws));
}
// we not use automatic finish, so attach to readable
state.onError = onErrorRS.bind(null, state, rs, cb);
state.onSuccess = onSuccessRS.bind(null, state, rs, cb);
rs.once('error', state.onError as any);
rs.once('end', state.onSuccess as any);
return T.thunkCanceller(() => cleanUpListenerRS(state, rs));
});
}
示例5: makeTask
export function readAVar<A>(avar: AVar<A>): Task<A> {
return makeTask(new AVarRead(avar));
}