mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
stream: prefer sync iterator in fromSync
When an input provides Symbol.iterator, fromSync() should consume the synchronous iterator instead of rejecting the input because it also exposes an asynchronous or promise-like protocol. Continue rejecting async-only iterables and promise/thenable-only inputs, but allow sync iterables that also define Symbol.asyncIterator or then(). Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: https://github.com/nodejs/node/pull/64294 Fixes: https://github.com/nodejs/node/issues/64292 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
8e1ab55ac4
commit
91b65a4fe8
2 files changed
+36
-5
No files matched your search
@@ -484,15 +484,20 @@ function fromSync(input) {
|
||||
return fromSync(input[toStreamable]());
|
||||
}
|
||||
|
||||
// Reject explicit async inputs
|
||||
if (isAsyncIterable(input)) {
|
||||
const isIterable = isSyncIterable(input);
|
||||
|
||||
// Reject explicit async-only inputs
|
||||
if (!isIterable && isAsyncIterable(input)) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'input',
|
||||
'a synchronous input (not AsyncIterable)',
|
||||
input,
|
||||
);
|
||||
}
|
||||
if (typeof input === 'object' && input !== null && typeof input.then === 'function') {
|
||||
if (!isIterable &&
|
||||
typeof input === 'object' &&
|
||||
input !== null &&
|
||||
typeof input.then === 'function') {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'input',
|
||||
'a synchronous input (not Promise)',
|
||||
@@ -501,7 +506,7 @@ function fromSync(input) {
|
||||
}
|
||||
|
||||
// Must be a SyncStreamable
|
||||
if (!isSyncIterable(input)) {
|
||||
if (!isIterable) {
|
||||
throw new ERR_INVALID_ARG_TYPE(
|
||||
'input',
|
||||
['string', 'ArrayBuffer', 'ArrayBufferView', 'Iterable', 'toStreamable'],
|
||||
|
||||
Reference in new issue
Block a user