Re: A promise that resolves after a delay.

2016-02-03 Thread Bob Myers
Easy to write yourself: ```js function wait(ms) { return function(v) { return new Promise(resolve => setTimeout(() => resolve(v), ms)); }; } ``` Now you can do ``` Promise.resolve(42) . then(wait(1000)) . then( /* cb */); ``` and the 42 will get passed through the callback. --Bob On T

Re: Specifying the Existential Operator using Abrupt Completion

2016-02-03 Thread Claude Pache
(Sorry for spam.) For reference in case someone searches for that topic in the archive; see: https://esdiscuss.org/topic/optional-chaining-aka-existential-operator-null-propagation > Le 3 févr. 2016 à 20:28, John Lenz a écrit : > > Did this happen? I would like to see some progress here. _

Re: Optional Chaining (aka Existential Operator, Null Propagation)

2016-02-03 Thread Claude Pache
> Le 3 févr. 2016 à 20:56, John Lenz a écrit : > > Can you reference something as to why the more obvious operators are > problematic? > > ?. That one (that I've used) must work, with the simple lookahead I've put in the lexical grammar, in order to continue to parse `x?.3:0` as today. > ?

Re: A promise that resolves after a delay.

2016-02-03 Thread Andrea Giammarchi
as pointed out offlist, the second line of my previous snippet was to shortcut the following: `new Promise(resolve => setTimeout(() => resolve("some value"), 1000));` assuming `"some value"` was static. In case it's not the `new Promise(r => setTimeout(r, 1000)).then(()=>"some value");` is the wa

Re: A promise that resolves after a delay.

2016-02-03 Thread C. Scott Ananian
Here's a quick plug for my `prfun` library (https://github.com/cscott/prfun) which implements this as `Promise.delay(1000)`. API at: https://github.com/cscott/prfun#promisedelaydynamic-value-int-ms--promise You can also do `return somepromise.delay(100)` which resolves to the same value as `samep

Re: A promise that resolves after a delay.

2016-02-03 Thread Andrea Giammarchi
Chiming in just to underline that setTimeout and setInterval accepts extra arguments since about ever so that the following is eventually all you need. ```js new Promise(r => setTimeout(r, 1000)); new Promise(r => setTimeout(r, 1000, "some value")); ``` Best Regards On Wed, Feb 3, 2016 at 8:5

Re: Optional Chaining (aka Existential Operator, Null Propagation)

2016-02-03 Thread Waldemar Horwat
On 02/03/2016 11:56, John Lenz wrote: Can you reference something as to why the more obvious operators are problematic? ?. ?[] ?() ?: Some of these have problems. For example, a?[]:b is already valid ECMAScript syntax and does something else. There is an analogous but subtler problem for

RE: A promise that resolves after a delay.

2016-02-03 Thread Domenic Denicola
I think this is a reasonable API, but ES is not the spec for it. ES does not have a proper concept of an event loop, and definitely not a proper concept of time. Note that setTimeout is not defined in ES, but instead in HTML: https://html.spec.whatwg.org/#dom-windowtimers-settimeout It might be

A promise that resolves after a delay.

2016-02-03 Thread JD Isaacks
I think it would be super useful to be able to do something like: Promise.after(1000).then( /* cb */ ); and have the promise resolve after 1000 milliseconds. The promise would just resolve with the same value (in this case 1000) but could easily delay resolving another value like so: Promise.af

Re: Optional Chaining (aka Existential Operator, Null Propagation)

2016-02-03 Thread John Lenz
Can you reference something as to why the more obvious operators are problematic? ?. ?[] ?() ?: On Fri, Jan 29, 2016 at 7:19 AM, Claude Pache wrote: > Hi, > > I have prepared a strawman for the `?.` operator: > > https://github.com/claudepache/es-optional-chaining/ > > If there is interest in t

Re: Specifying the Existential Operator using Abrupt Completion

2016-02-03 Thread John Lenz
Did this happen? I would like to see some progress here. On Wed, Jan 13, 2016 at 10:51 AM, Claude Pache wrote: > > Le 13 janv. 2016 à 18:06, C. Scott Ananian a > écrit : > > On Wed, May 21, 2014 at 8:33 AM, Claude Pache > wrote: > >> >> I have thought about the right semantics (and the issue