本文整理汇总了TypeScript中stream.PassThrough.emit方法的典型用法代码示例。如果您正苦于以下问题:TypeScript PassThrough.emit方法的具体用法?TypeScript PassThrough.emit怎么用?TypeScript PassThrough.emit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.PassThrough
的用法示例。
在下文中一共展示了PassThrough.emit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
(res: http.IncomingMessage) => {
if (res.statusCode === 200) {
res.pipe(fileStream);
return;
}
fileStream.emit('error', new Error(STATUS_CODES[res.statusCode]));
fileStream.emit('end');
},
示例2: function
async function() {
const expectedResponse: RpcResponse = { result: '...', error: null, id: null }
const message = new PassThrough()
message.end(JSON.stringify(expectedResponse))
this.request
.callsArgWith(1, message)
.returns(new PassThrough())
try {
const promise = RpcClient({ password: 'password' })(Help())
message.emit('error', new Error())
const result = await promise
throw new Error('Unreachable')
} catch (error) {
expect(error)
.to.be.an.instanceof(Error)
.and.to.not.be.an.instanceof(RpcError)
.and.to.not.have.property('message', 'Unreachable')
}
},
示例3: callback
function callback(err: Error|null, resources, next) {
if (err) {
stream.emit('error', err);
return;
}
for (let i = 0; i < resources.length; ++i) {
if (ended(stream)) {
return;
}
if (resources[i] === null) {
continue;
}
stream.push(resources[i]);
pushCount++;
if (pushCount === maxResults) {
stream.end();
}
}
if (ended(stream)) {
return;
}
if (!next) {
stream.end();
return;
}
// When pageToken is specified in the original options, it will overwrite
// the page token field in the next request. Therefore it must be cleared.
if ('pageToken' in options) {
delete options.pageToken;
}
if (stream.isPaused()) {
request = next;
started = false;
} else {
setImmediate(apiCall, next, options, callback);
}
}
示例4: setTimeout
setTimeout(() => {
readStream.emit('response', {
statusCode: 404,
statusMessage: 'TEST MESSAGE - 404',
});
}, 10);
示例5: Task
const emitErr = new Task(ctx => Promise.resolve(str.emit('error', err)));
示例6: setImmediate
setImmediate(() => {
str.emit('error', err);
str.end();
});
示例7:
}).then(state => {
str.emit('error', err);
return sink.onEnd(state);
});