I'm mostly using programming languages like Scala and JavaScript. I'm trying to understand the similarities and differences in how async reactive programming is used in both languages. Can you help me?
I'm not taking any particular Js Promise
framework because it seems many implement the similar specifications (like Promise/A). I've only used Q so far.
It seems that in Javascript we call a Deferred
the object we resolve to complete a Promise
.
In Scala, it seems the Promise
is the object you resolve to get a Future
monad.
Can someone tell me if this is right? Is there any good reason for a different usage of the term Promise
between Js and Scala?
Also, in Scala we usually chain Future
monads with further computations using operators like map
and flatMap
(also called bind
in Haskell). What is the equivalent of these in Js?
I may be wrong but it appears to me that in Js the then
on a Promise
kind of handle both map
and flatMap
operators right? If so, is it possible to obtain a promise of promise of result
in Js? Like we can get a Future[Future[Result]]
in Scala (which can be flattened to a Future[Result]
anyway).
Is Js Promise
a monad? It kind of seems so even if the method names do not really match those we find on monad literature.