Fork me on GitHub
#funcool
<
2015-11-05
>
jfntn17:11:22

Hi @niwinz, I was looking for a portable promises abstraction and found your promesa and promissum libraries.

jfntn17:11:48

Was wondering if you’d considered bridging the gap and provide some kind of portable interface?

niwinz17:11:15

Hi @jfntn they are "almost" portable

niwinz17:11:35

I mean that the differences between the two promises are just becuase of platform differences

niwinz17:11:27

promesa (cljs) can't do blocking calls because them are imposible in js...

jfntn17:11:45

sur ebut with cljc they could be packaged together now under the same api

niwinz17:11:47

and the promise constructor differes a little bit because in cljs/js an error can be anything so is no way to distinguish between values, because of this the cljs constructor receives 2 callbacks and the clj one...

jfntn17:11:14

oh I missed that

niwinz17:11:25

They are packaged separatedly because promissum requires jdk8

niwinz17:11:32

but promesa not requires it

niwinz17:11:46

Maybe is possible package them in one unique library, but at this moment I don't know if that a proper way...

jfntn17:11:56

yeah I wonder if you could set up your maven deps so that the cljs part wouldn’t require jdk8

niwinz17:11:27

Hmm, I will think about, maybe you are right and package them together seems a good idea

jfntn17:11:29

Cool, could you elaborate a little bit on the difference in error handling that requires different promise constructors? I’m not sure I understand why this is necessary

niwinz17:11:21

in clojure/jdk impl

niwinz17:11:36

an error can be only an instance of Exception/Throwable

niwinz17:11:43

but in cljs/js can be any object

jfntn17:11:52

oh I didn’t know that 😛

jfntn17:11:09

so you can throw anything in cljs?

jfntn17:11:28

hmm, wouldn’t you be able to catch it though?

niwinz17:11:09

yes, js is dynamic lang and you can't specify the type in catch block

niwinz17:11:04

because of that, in cljs promise constructor receives two callbacks

niwinz17:11:10

one for resolve and other for reject

niwinz17:11:47

because it there isnt' any way to distinguish if an value is an error or an valid value

niwinz17:11:03

in clj/jdk this not happens

niwinz17:11:15

and the resolve function is fully polymorphic

niwinz17:11:44

In any case I'm pretty convinced now that differences can be handled properly in one unique package

niwinz17:11:04

so I surely start working in joining them

jfntn17:11:39

Yeah I’m still not sure why you wouldn’t be able to catch any object getting thrown in a promise’s fn ctor

jfntn17:11:37

Ok cool, I’m sure this will be really helpful, I’ve been working on a protable ring-cps http client and don’t want to add promises to the middleware stack, but they would be really useful as adapters 😉