Skip to content

Commit

Permalink
Spec teardown and remaining Subscriber attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
domfarolino committed Jan 2, 2024
1 parent 2c3358c commit 96abe1e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ Each {{Subscriber}} has a <dfn for=Subscriber>error callback</dfn>, which is an
Each {{Subscriber}} has a <dfn for=Subscriber>complete callback</dfn>, which is a
{{VoidFunction}}-or-null.

Each {{Subscriber}} has a <dfn for=Subscriber>teardown callbacks</dfn>, which is a [=list=] of
{{VoidFunction}}s, initially empty.

Each {{Subscriber}} has a <dfn for=Subscriber>complete or error controller</dfn>, which is an
{{AbortController}}.

Expand All @@ -176,6 +179,12 @@ Each {{Subscriber}} has a <dfn for=Subscriber>active</dfn> boolean, initially tr
Note: This is a bookkeeping variable to ensure that a {{Subscriber}} never calls any of the
callbacks it owns after it has been [=close a subscription|closed=].

The <dfn attribute for=Subscriber><code>active</code></dfn> getter steps are to return [=this=]'s
[=Subscriber/active=] boolean.

The <dfn attribute for=Subscriber><code>signal</code></dfn> getter steps are to return [=this=]'s
[=Subscriber/signal=].

<div algorithm>
The <dfn for=Subscriber method><code>next(|value|)</code></dfn> method steps are:

Expand Down Expand Up @@ -227,6 +236,21 @@ callbacks it owns after it has been [=close a subscription|closed=].
1. [=AbortController/Signal abort=] [=this=]'s [=Subscriber/complete or error controller=].
</div>

<div algorithm>
The <dfn for=Subscriber method><code>addTeardown(|teardown|)</code></dfn> method steps are:

1. If [=this=]'s [=relevant global object=]'s [=associated Document=] is not [=Document/fully
active=], then return.

1. If [=this=]'s [=Subscriber/active=] is true, then [=list/append=] |teardown| to [=this=]'s
[=Subscriber/teardown callbacks=] list.

1. Otherwise, [=invoke=] |teardown|.

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, then [=report
the exception=] |E|.
</div>

<div algorithm>
To <dfn>close a subscription</dfn> given a {{Subscriber}} |subscriber|, run these steps:

Expand Down Expand Up @@ -398,6 +422,25 @@ can be passed in by natively-constructed {{Observable}}s.
Note: This can happen when {{SubscribeOptions}}'s {{SubscribeOptions/signal}} is already
[=AbortSignal/aborted=].

1. Otherwise, [=AbortSignal/add=] the following algorithm to |subscriber|'s
[=Subscriber/signal=]:

1. [=close a subscription|Close=] |subscriber|.

1. [=list/For each=] |teardown| of |subscriber|'s [=Subscriber/teardown callbacks=] sorted in
reverse insertion order:

1. If |subscriber|'s [=relevant global object=]'s [=associated Document=] is not
[=Document/fully active=], then abort these steps.

Note: This step runs repeatedly because each |teardown| could result in the above
{{Document}} becoming inactive.

1. [=Invoke=] |teardown|.

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, call
|subscriber|'s {{Subscriber/error()}} method with |E|.

1. [=Invoke=] [=this=]'s [=Observable/subscribe callback=] with |subscriber|.

If <a spec=webidl lt="an exception was thrown">an exception |E| was thrown</a>, call
Expand Down

0 comments on commit 96abe1e

Please sign in to comment.