Skip to content

Commit f1e2244

Browse files
LanayxMangelMaxime
andauthored
[JS] Support for AsyncIterator protocol (#4336)
Co-authored-by: Mangel Maxime <me@mangelmaxime.fr>
1 parent 0a2b90e commit f1e2244

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/Fable.Core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
### Added
1919

2020
* [Python] Added collection protocol markers and interfaces for Python interop (by @dbrattli)
21+
* [JS] Add `AsyncIterator`, `AsyncGenerator`, and `IteratorResult` interfaces for the AsyncIterator protocol (by @Lanayx)
2122

2223
### Fixed
2324

src/Fable.Core/Fable.Core.JS.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,22 @@ module JS =
395395
and [<AllowNullLiteral>] AsyncIterable<'T> =
396396
inherit AsyncIterable
397397

398+
[<Emit("$0[Symbol.asyncIterator]()")>]
399+
abstract asyncIterator: unit -> AsyncIterator<'T>
400+
401+
and [<AllowNullLiteral>] IteratorResult<'T> =
402+
abstract value: 'T with get, set
403+
abstract ``done``: bool with get, set
404+
405+
and [<AllowNullLiteral>] AsyncIterator<'T> =
406+
abstract next: unit -> Promise<IteratorResult<'T>>
407+
abstract ``return``: value: 'T -> Promise<IteratorResult<'T>>
408+
abstract throw: e: obj -> Promise<IteratorResult<'T>>
409+
410+
and [<AllowNullLiteral>] AsyncGenerator<'T> =
411+
inherit AsyncIterator<'T>
412+
inherit AsyncIterable<'T>
413+
398414
and [<AllowNullLiteral>] Promise<'T> =
399415
abstract ``then``: ?onfulfilled: ('T -> 'TResult) * ?onrejected: (obj -> 'TResult) -> Promise<'TResult>
400416

0 commit comments

Comments
 (0)