From ad90abe4a720e1a681e6e5e6fac07f0b97900b9c Mon Sep 17 00:00:00 2001 From: Dominic Farolino Date: Sat, 4 May 2024 14:49:13 -0400 Subject: [PATCH] Spec the `last()` operator --- spec.bs | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/spec.bs b/spec.bs index 614423a..3d8a171 100644 --- a/spec.bs +++ b/spec.bs @@ -1323,7 +1323,7 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w : [=internal observer/next steps=] :: 1. [=Resolve=] |p| with the passed in value. - + 1. [=AbortController/Signal abort=] |controller|. : [=internal observer/error steps=] @@ -1348,7 +1348,48 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w
The last(|options|) method steps are: - 1. TODO: Spec this and use |options|. + 1. Let |p| [=a new promise=]. + + 1. If |options|'s {{SubscribeOptions/signal}} is not null: + + 1. If |options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then: + + 1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort + reason=]. + + 1. Return |p|. + + 1. [=AbortSignal/add|Add the following abort algorithm=] to |options|'s + {{SubscribeOptions/signal}}: + + 1. [=Reject=] |p| with |options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort + reason=]. + + 1. Let |lastValue| be an {{any}}-or-null, initially null. + + 1. Let |hasLastValue| be a [=boolean=], initially false. + + 1. Let |observer| be a new [=internal observer=], initialized as follows: + + : [=internal observer/next steps=] + :: 1. Set |hasLastValue| to true. + + 1. Set |lastValue| to the passed in value. + + : [=internal observer/error steps=] + :: [=Reject=] |p| with the passed in error. + + : [=internal observer/complete steps=] + :: 1. If |hasLastValue| is true, [=resolve=] |p| with |lastValue|. + + 1. Otherwise, [=resolve=] |p| with {{undefined}}. + + Note: See the note in {{Observable/first()}}. + + 1. Subscribe to [=this=] given |observer| + and |options|. + + 1. Return |p|.