Skip to content

Commit

Permalink
Improve iterable detection
Browse files Browse the repository at this point in the history
Thanks, @kimamula! (See #256)
  • Loading branch information
andywer committed Jun 23, 2020
1 parent 300342e commit 6f41e98
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/serializers/iterators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const DefaultIteratorSerializer = (rootSerializer: Serializer): Serialize
})

export const isIterator = (thing: any): thing is Iterator<any> | AsyncIterator<any> =>
thing && typeof thing === "object" && "next" in thing && typeof thing.next === "function"
thing && typeof thing === "object" && (
typeof thing.next === "function" ||
typeof (thing as AsyncIterable<unknown>)[Symbol.asyncIterator] === "function"
)

export const isSerializedIterator = (thing: any): thing is SerializedIterator =>
thing && typeof thing === "object" && "__iterator_marker" in thing && thing.__iterator_marker === "$$iterator"

0 comments on commit 6f41e98

Please sign in to comment.