这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
ready
只读特性在
WritableStreamDefaultWriter
interface returns a
Promise
that resolves when the desired size of the stream's internal queue transitions from non-positive to positive, signaling that it is no longer applying backpressure.
var promise = writableStreamDefaultWriter.ready;
A
Promise
.
The following example shows two uses of the
ready
property. The first uses
ready
以确保
WritableStream
is done writing and thus able to receive data before sending a binary chunk. The second also checks whether the the
WritableStream
is done writing, but this time because the writing must be finished before the writer can be closed.
function sendMessage(message, writableStream) {
// defaultWriter is of type WritableStreamDefaultWriter
var defaultWriter = writableStream.getWriter();
var encoder = new TextEncoder();
var encoded = encoder.encode(message, {stream: true});
encoded.forEach(function(chunk) {
// Make sure the stream and its writer are able to
// receive data.
defaultWriter.ready
.then(function() {
defaultWriter.write(chunk)
.then(function() {
console.log("Chunk written to sink.);
})
.catch(function(err) {
console.log("Chunk error: " + err);
});
});
// Call ready again to ensure that all chunks are written
// before closing the writer.
defaultWriter.ready
.then(function() {
defaultWriter.close()
.then(function() {
console.log("All chunks written");
})
.catch(function(err) {
console.log("Stream error: " + err);
});
});
});
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
流
The definition of 'ready' in that specification. |
实时标准 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ready
|
Chrome 59 | Edge 16 | Firefox No | IE No | Opera 46 | Safari ? | WebView Android 59 | Chrome Android 59 | Firefox Android No | Opera Android 43 | Safari iOS ? | Samsung Internet Android 7.0 |
完整支持
不支持
兼容性未知
实验。期望将来行为有所改变。
WritableStreamDefaultWriter
abort()
close()
ready
releaseLock()
write()