本文整理汇总了TypeScript中stream.Transform.once方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Transform.once方法的具体用法?TypeScript Transform.once怎么用?TypeScript Transform.once使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Transform
的用法示例。
在下文中一共展示了Transform.once方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: TimeoutError
const handleRequest = (request: http.ClientRequest) => {
if (shouldAbort) {
request.abort();
return;
}
currentRequest = request;
request.on('error', error => {
if (request.aborted || error.message === 'socket hang up') {
return;
}
if (error instanceof TimedOutTimeoutError) {
error = new TimeoutError(error, timings, options);
} else {
error = new RequestError(error, options);
}
if (emitter.retry(error) === false) {
emitError(error);
}
});
timings = timer(request);
uploadProgress(request, emitter, uploadBodySize);
if (options.gotTimeout) {
// TODO: Properly type this. `preNormalizeArguments` coerces `gotTimeout` to `Delays`.
timedOut(request, options.gotTimeout as Delays, options);
}
emitter.emit('request', request);
const uploadComplete = () => {
request.emit('upload-complete');
};
try {
if (is.nodeStream(options.body)) {
options.body.once('end', uploadComplete);
options.body.pipe(request);
options.body = undefined;
} else if (options.body) {
request.end(options.body, uploadComplete);
} else if (input && (options.method === 'POST' || options.method === 'PUT' || options.method === 'PATCH')) {
input.once('end', uploadComplete);
input.pipe(request);
} else {
request.end(uploadComplete);
}
} catch (error) {
emitError(new RequestError(error, options));
}
};