Re: Stream + async await

2017-08-02 Thread Jan-Ivar Bruaroey
flow. .: Jan-Ivar :. On 8/1/17 4:29 PM, Domenic Denicola wrote: That is not why. -------- *From:* Jan-Ivar Bruaroey *Sent:* Aug 1, 2017 3:47 PM *To:* es-discuss@mozilla.org *Subject:* Re: Stream + async await Because a promi

Re: Stream + async await

2017-08-01 Thread Jan-Ivar Bruaroey
Because a promise is not a control surface of the asynchronous action fulfilling it; confuses owner with consumer. https://stackoverflow.com/a/41417429/918910 .: Jan-Ivar :. On 7/31/17 7:35 AM, T.J. Crowder wrote: Related: https://esdiscuss.org/topic/how-about-awaiting-arrays (particularly th

Re: Cancel Promise pattern (no cancellable promises)

2017-01-12 Thread Jan-Ivar Bruaroey
Cancellable promises is dead. Please don't hijack this thread discussing them. Thanks, .: Jan-Ivar :. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Cancel Promise pattern (no cancellable promises)

2017-01-04 Thread Jan-Ivar Bruaroey
"resumption" option. PTAL! Some comments on the earlier thread here: - The above fiddle suffers no accumulative "memory leak" problems. GC just works. - Synchronous inspection is necessary in multi-threaded cancellation only, not JS. .: Jan-Ivar :. On 10/26/16 10:41

Re: Cancel Promise pattern (no cancellable promises)

2016-11-01 Thread Jan-Ivar Bruaroey
On 10/31/16 2:39 PM, Herby Vojčík wrote: Jan-Ivar Bruaroey wrote: On 10/28/16 8:39 AM, Bergi wrote: Jan-Ivar Bruaroey wrote: If you try the fiddle - http://jsfiddle.net/jib1/jz33qs32/ - you'll see cancelling terminates the chain. If you intersperse non-cancellable operations, there&#

Re: Cancel Promise pattern (no cancellable promises)

2016-10-31 Thread Jan-Ivar Bruaroey
On 10/28/16 8:39 AM, Bergi wrote: Jan-Ivar Bruaroey wrote: If you try the fiddle - http://jsfiddle.net/jib1/jz33qs32/ - you'll see cancelling terminates the chain. If you intersperse non-cancellable operations, there'd be a delay if cancel is detected during those. Yes, that

Re: Cancel Promise pattern (no cancellable promises)

2016-10-27 Thread Jan-Ivar Bruaroey
On 10/27/16 4:25 PM, Bergi wrote: But you've got some good and important points. Thanks! Things to note: - Cancellation is targeted to specific operations (no "cancel chain" ambition). I'd however love to be able to cancel specific chaining operations, i.e. `then` callbacks. If you try t

Re: Cancel Promise pattern (no cancellable promises)

2016-10-27 Thread Jan-Ivar Bruaroey
Likely this would be more convincing without a bug. Here is the correct wait function: let wait = (ms, cancel = new Promise(() => {})) => { let id, both = x => [x, x]; cancel.then(...both(() => clearTimeout(id))); return Promise.race([new Promise(resolve => id = setTimeout(resolve, ms)),

Cancel Promise pattern (no cancellable promises)

2016-10-26 Thread Jan-Ivar Bruaroey
This is an alternative to cancellable promises that relies entirely on existing JavaScript. I'm posting this here in hopes to bring the discussion back to practical use cases and minimal needs. Example: Here's a setTimeout wrapper with cancellation, using a regular promise as a cancellation

Re: A promise that resolves after a delay.

2016-02-04 Thread Jan-Ivar Bruaroey
On 2/3/16 11:39 PM, Bob Myers wrote: Promise.resolve(42) . then(wait(1000)) . then( /* cb */); With ES6 I prefer the straightforward: var wait = ms => new Promise(resolve => setTimeout(resolve, ms)); Promise.resolve(42) . then(() => wait(1000)).then(() => { /* cb */ }); Too simple t

Single destructuring argument to an arrow function

2015-03-19 Thread Jan-Ivar Bruaroey
Hi group! First post, so be gentle. I love how arrow functions allow single arguments to be passed without parenthesis, so I expected this to work: Promise.all([true, false]).then([foo, bar] => console.log(foo +”, "+ bar)); but it doesn't: SyntaxError: invalid arrow-function argume