Skip to content

Commit

Permalink
from(): Close synchronous iterators properly (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino authored Jan 27, 2025
1 parent 2538ee1 commit 8a8c950
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ urlPrefix: https://tc39.es/ecma262/#; spec: ECMASCRIPT
type: dfn
text: current realm
text: Object; url: sec-object-type
text: normal completion; url: sec-normalcompletion
text: throw completion; url: sec-throwcompletion
text: normal completion; url: sec-completion-record-specification-type
text: NormalCompletion; url: sec-normalcompletion
text: throw completion; url: sec-completion-record-specification-type
url: sec-returnifabrupt-shorthands
text: ?
text: !
Expand Down Expand Up @@ -502,6 +503,9 @@ An <dfn>internal observer</dfn> is a [=struct=] with the following [=struct/item
Otherwise, return a [=new=] {{Observable}} whose [=Observable/subscribe callback=] is an
algorithm that takes a {{Subscriber}} |subscriber| and does the following:

1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=] is
[=AbortSignal/aborted=], then return.

1. Let |iteratorRecordCompletion| be [$GetIterator$](|value|, sync).

1. If |iteratorRecordCompletion| is a [=throw completion=], then run |subscriber|'s
Expand All @@ -510,6 +514,14 @@ An <dfn>internal observer</dfn> is a [=struct=] with the following [=struct/item

1. Let |iteratorRecord| be [=!=] |iteratorRecordCompletion|.

1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=] is
[=AbortSignal/aborted=], then return.

1. [=AbortSignal/add|Add the following abort algorithm=] to |subscriber|'s
[=Subscriber/subscription controller=]'s [=AbortController/signal=]:

1. Run [$IteratorClose$](|iteratorRecord|, [=NormalCompletion=](UNUSED)).

1. [=iteration/While=] true:

1. Let |next| be [$IteratorStepValue$](|iteratorRecord|).
Expand All @@ -529,6 +541,9 @@ An <dfn>internal observer</dfn> is a [=struct=] with the following [=struct/item

1. Run |subscriber|'s {{Subscriber/next()}} given |next|.

1. If |subscriber|'s [=Subscriber/subscription controller=]'s [=AbortController/signal=]
is [=AbortSignal/aborted=], then [=iteration/break=].

1. <i id=from-promise-conversion><b>From Promise</b></i>: If [$IsPromise$](|value|) is true,
then:

Expand Down

0 comments on commit 8a8c950

Please sign in to comment.