Resolve or reject a deferred or promise multiple times

352 views
Skip to first unread message

sight...@gmail.com

unread,
Nov 25, 2014, 4:13:11 AM11/25/14
to def...@googlegroups.com
Hey guys. At first thank you for this awesome piece of work. DeftJs solved so many issues i had with vanilla extjs architecture.

My question is: Is it possible to resolve or reject a deferred/promise multiple times, so the registered callbacks gets called multiple times?

Thx in advance.

ExtJs-Version: 4.2.0
DeftJs-Version: 0.9.1 (stable i think)

Brian Kotek

unread,
Nov 25, 2014, 11:14:10 AM11/25/14
to deftjs
I'm fairly sure that if you call when()/then()/finally() on a Promise that is already resolved (or rejected) it will immediately trigger any chained Promises or callbacks.

--
Deft JS home page: http://deftjs.org/
Wiki: https://github.com/deftjs/DeftJS/wiki
For rules and tips on asking questions on the Deft JS mailing list: https://github.com/deftjs/DeftJS/wiki/Asking-Questions-on-the-Mailing-List
---
You received this message because you are subscribed to the Google Groups "Deft JS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deftjs+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/deftjs/91c3e15c-e09f-4d36-882f-7b43f35cf5f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brian Kotek

unread,
Nov 25, 2014, 11:15:45 AM11/25/14
to deftjs
Hmm but to add, if you're asking if you can actually call resolve() or reject() again on a Promise that is already resolved or rejected, I'm not sure (just because I've never done it). My *guess* is that it would trigger the callbacks, but you'd want to double check to be sure.

John Yanarella

unread,
Nov 25, 2014, 11:42:26 AM11/25/14
to def...@googlegroups.com
Great to hear Deft JS has been useful for you!

No, by design a Promise can only resolve / reject once.

A Promise represents a future value (i.e. a value that may not yet be available). Just one value, though. Not subsequent changes to that value. Promises are not intended to be a general purpose notification system like events, signals, or streams.

Check out Domenic’s presentation to the NY Times on Promises for some discussion on this: 


In terms of the primitives offered by the Ext JS framework, you may want to create an instance of Observable (an event bus) and attach callbacks to that.  There are also many third party (non Ext JS specific) JS libraries available that offer nice implementations of signals and streams.

Best regards,

-J


Reply all
Reply to author
Forward
0 new messages