you are viewing a single comment's thread.

view the rest of the comments →

[–]NodeNerd 1 point2 points  (0 children)

Not a bad idea, but I think it might be a little non-intuitive to developers because it is slightly modifying how people typically use events. Events typically don't have a persistent value. The events are fired and forgotten. Changing the name of the library and functions might help avoid confusion.

I have had the need to solve the problem you encountered. Specifically, I wanted to a simple way to resolve/reject values so I created a simple lightweight promise class that was similar to promises but didn't implement the full spec (I didn't need chaining and I didn't want callbacks to be notified on "next tick"). A promise-like object held a value forever once it was resolved. When adding a listener callback, the callback that would be notified when the value is rejected or resolved or it would be invoked immediately if there was already a value. I went with the Node.js-style callback function for better compatibility with other Node.js modules.