Promise/Future: asynchrony in 'then'

Tab Atkins Jr. jackalmage at gmail.com
Fri May 3 07:46:47 PDT 2013


On Fri, May 3, 2013 at 1:53 AM, Claus Reinke <claus.reinke at talk21.com> wrote:
> That part I wouldn't be so sure about: in all monads, the .of equivalent
> is effect-free (in an IO monad, it does no IO; in a non-determinism
> monad, it is deterministic; in a failure/exception monad, it does not
> fail; in a count-steps monad, it doesn't count).
> If you look at those identity laws at the top again, you'll see that
> Promise.of cannot introduce a delay for these laws to work out
> (otherwise, the left- and right-hand sides would have different
> numbers of ticks/turns).

As I said, the number of ticks is unobservable if you're writing
effect-free code.

If you're not writing effect-free code, then as I said before, keeping
the number of ticks the same regardless of the state of the promise
when you call .then() on it is important for consistency, so it's easy
to reason about how your code will run.

~TJ


More information about the es-discuss mailing list