Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(op_crate/fetch): add back ReadableStream.getIterator and deprecate #9146

Merged
merged 1 commit into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cli/tests/unit/streams_deprecated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";

unitTest(async function symlinkSyncPerm() {
const rs = new ReadableStream<string>({
start(controller) {
controller.enqueue("hello ");
controller.enqueue("deno");
controller.close();
},
});

for await (const chunk of rs.getIterator()) {
assertEquals(typeof chunk, "string");
}
});
1 change: 1 addition & 0 deletions cli/tests/unit/unit_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import "./response_test.ts";
import "./signal_test.ts";
import "./stat_test.ts";
import "./stdio_test.ts";
import "./streams_deprecated.ts";
import "./symlink_test.ts";
import "./sync_test.ts";
import "./text_encoding_test.ts";
Expand Down
10 changes: 9 additions & 1 deletion op_crates/fetch/11_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,6 @@
// 3.5.6.8 Otherwise, support BYOB Reader
/** @type {Deferred<void>} */
const closedPromise = reader[_closedPromise];
console.log("closedPromise rejected");
closedPromise.reject(e);
setPromiseIsHandledToTrue(closedPromise.promise);
}
Expand Down Expand Up @@ -3097,6 +3096,15 @@
return readableStreamCancel(this, reason);
}

/**
* @deprecated TODO(@kitsonk): Remove in Deno 1.8
* @param {ReadableStreamIteratorOptions=} options
* @returns {AsyncIterableIterator<R>}
*/
getIterator(options = {}) {
return this[Symbol.asyncIterator](options);
}

/**
* @param {ReadableStreamGetReaderOptions=} options
* @returns {ReadableStreamDefaultReader<R>}
Expand Down
6 changes: 6 additions & 0 deletions op_crates/fetch/lib.deno_fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ declare class ByteLengthQueuingStrategy
interface ReadableStream<R = any> {
readonly locked: boolean;
cancel(reason?: any): Promise<void>;
/**
* @deprecated This is no longer part of the Streams standard and the async
* iterable should be obtained by just using the stream as an
* async iterator.
*/
getIterator(options?: { preventCancel?: boolean }): AsyncIterableIterator<R>;
getReader(): ReadableStreamDefaultReader<R>;
pipeThrough<T>(
{ writable, readable }: {
Expand Down