diff --git a/spec.bs b/spec.bs index 69ae73d..614423a 100644 --- a/spec.bs +++ b/spec.bs @@ -373,7 +373,8 @@ interface Observable { Promise> toArray(optional SubscribeOptions options = {}); Promise forEach(Visitor callback, optional SubscribeOptions options = {}); Promise every(Predicate predicate, optional SubscribeOptions options = {}); - // Maybe? Promise first(optional SubscribeOptions options = {}); + Promise first(optional SubscribeOptions options = {}); + Promise last(optional SubscribeOptions options = {}); Promise find(Predicate predicate, optional SubscribeOptions options = {}); Promise some(Predicate predicate, optional SubscribeOptions options = {}); Promise reduce(Reducer reducer, optional any initialValue, optional SubscribeOptions options = {}); @@ -1293,6 +1294,63 @@ For now, see [https://github.com/wicg/observable#operators](https://github.com/w 1. Return |p|. +
+ The first(|options|) method steps are: + + 1. Let |p| [=a new promise=]. + + 1. Let |controller| be a [=new=] {{AbortController}}. + + 1. Let |internal options| be a new {{SubscribeOptions}} whose {{SubscribeOptions/signal}} is the + result of [=creating a dependent abort signal=] from the list «|controller|'s + [=AbortController/signal=], |options|'s {{SubscribeOptions/signal}} if non-null», using + {{AbortSignal}}, and the [=current realm=]. + + 1. If |internal options|'s {{SubscribeOptions/signal}} is [=AbortSignal/aborted=], then: + + 1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s + [=AbortSignal/abort reason=]. + + 1. Return |p|. + + 1. [=AbortSignal/add|Add the following abort algorithm=] to |internal options|'s + {{SubscribeOptions/signal}}: + + 1. [=Reject=] |p| with |internal options|'s {{SubscribeOptions/signal}}'s [=AbortSignal/abort + reason=]. + + 1. Let |internal observer| be a new [=internal observer=], initialized as follows: + + : [=internal observer/next steps=] + :: 1. [=Resolve=] |p| with the passed in value. + + 1. [=AbortController/Signal abort=] |controller|. + + : [=internal observer/error steps=] + :: [=Reject=] |p| with the passed in error. + + : [=internal observer/complete steps=] + :: [=Resolve=] |p| with {{undefined}}. + + Note: This is only reached when the source {{Observable}} completes *before* it emits a + single value; in this case, resolving with {{undefined}} is harmless but makes it + difficult to distinguish between the first value trule being {{undefined}} and premature + completion. See #132 for + discussion on this. + + 1. Subscribe to [=this=] given |internal + observer| and |internal options|. + + 1. Return |p|. + +
+ +
+ The last(|options|) method steps are: + + 1. TODO: Spec this and use |options|. +
+
The find(|predicate|, |options|) method steps are: