本文整理匯總了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));
}
};