本文整理汇总了TypeScript中src/streams/ReadableStreamReader.read函数的典型用法代码示例。如果您正苦于以下问题:TypeScript read函数的具体用法?TypeScript read怎么用?TypeScript read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
return reader.read().then(function (result: ReadResult<Event>) {
assert.strictEqual(result.value, appleEvent);
return reader.read().then(function (result: ReadResult<Event>) {
assert.strictEqual(result.value, orangeEvent);
});
});
示例2: readNext
function readNext(): Promise<void> {
return reader.read().then(function (result: ReadResult<number>) {
if (result.done) {
return Promise.resolve();
}
else {
results.push(result.value);
return readNext();
}
});
}
示例3:
return stream.writable.write(testValue).then(function () {
return reader.read().then(function (result: ReadResult<number>) {
assert.strictEqual(result.value, testValue.charCodeAt(0));
});
});
示例4: registerSuite
registerSuite({
name: 'EventedStreamSource',
beforeEach() {
emitter = new Evented();
source = new EventedStreamSource(emitter, 'testEvent');
stream = new ReadableStream<Event>(source);
reader = stream.getReader();
return stream.started;
},
start() {
emitter.emit(testEvent);
return reader.read().then(function (result: ReadResult<Event>) {
assert.strictEqual(result.value, testEvent,
'Event read from stream should be the same as the event emitted by emitter');
});
},
'event array'() {
let appleEvent = {
type: 'apple',
test: 'value'
};
let orangeEvent = {
type: 'orange',
test: 'value'
};