You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After discussion with @jhusain, it's been determined that the signature should be "generator in generator out", and that Generator should have an additional dispose method on it.
Here's the basics for purposes of this issue (the @zenparsing repo will be the "official" version of the spec though, it's just not updated as of the time of this issue creation):
// rough interface (could be more "genericky", I suppose)interfaceGenerator{next(value:any):IteratorResult<any>return(value:any):IteratorResult<any>throw(value:any):IteratorResult<any>dispose():void}letsubscription:Generator=myObservable.subscribe(observer:Generator);
With this there will be three methods of unsubscribing:
subscription.return(x) - signal success to the consumer, then clean up.
subscription.throw(err) - signal an error to the consumer, then clean up.
subscription.dispose() - just clean up
Why?
This enables the support of generator functions as observers:
Both will work, the latter is preferred in most cases, but the primed generator pattern can prove useful for things like parsers or other state machines that may built up values to clean up as it processes incoming values.
* Note: prime is a function that pumps one "next" value at the generator to get it started, since generators are initialized lazily with the first next call to their returned iterators.
I no longer think this is the appropriate direction for this library or the observable spec. Closing for now. See discussion here: tc39/proposal-observable#35 (comment)
FWIW: This subscription returned by the subscriber methods will remain as-is for now. I believe the behavior of disposal will change to be more on-par with current RxJS, however. And I'd like to add a subscribeWithGenerator method (or some such named thing) that primes the generator function passed, and returns a generator as a subscription object.
Per #28, we need to match observable spec defined at http://github.com/zenparsing/es-observable
After discussion with @jhusain, it's been determined that the signature should be "generator in generator out", and that Generator should have an additional
dispose
method on it.Here's the basics for purposes of this issue (the @zenparsing repo will be the "official" version of the spec though, it's just not updated as of the time of this issue creation):
With this there will be three methods of unsubscribing:
subscription.return(x)
- signal success to the consumer, then clean up.subscription.throw(err)
- signal an error to the consumer, then clean up.subscription.dispose()
- just clean upWhy?
This enables the support of generator functions as observers:
which would be (roughly) synonymous with:
Both will work, the latter is preferred in most cases, but the primed generator pattern can prove useful for things like parsers or other state machines that may built up values to clean up as it processes incoming values.
* Note:
prime
is a function that pumps one "next" value at the generator to get it started, since generators are initialized lazily with the firstnext
call to their returned iterators./cc @jhusain
ref:
The text was updated successfully, but these errors were encountered: