Promise.sync() vs Promise.value()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Promise.sync() vs Promise.value()

shanmuha
Are there any guidelines on when to use Promise.sync() and Promise.value()?
is the value in Promise.value() 'evaluated' everytime the Promise is resolved?
if so then whats the difference between Promise.sync() and Promise.value()?
My use case:
when returning a function that operates on Ratpack context is  returned as a Promise via sync(), the unit tests relying on it via RequestFixture fails (the code from sync() actually returns a NullPointerException). when the same function is returned via value(),  unit test works as expected.

Many thanks for a wonderful library!
Regards,
Shanmu.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Promise.sync() vs Promise.value()

Luke Daley
Administrator
Hi Shanmu,

Promise.sync() takes a function, that is invoked every time the promise is subscribed to. You can think of Promise.value() as syntactic sugar for Promise.sync() where the function always returns that value.

Regarding the NPE, my guess is that you're effectively doing Promise.sync(null), which will indeed throw an exception.
Loading...