Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Well actually the event occurs several times but it doesn't really make sense to listen to multiple of them so I only have a function to catch the next one.
-
I'm using rxjs observables and unsubscribing upon invocation. It's a hack, a horrible one I must say, judging by how difficult it is to unsub, but it works. I wonder what others do tho.
Edit: I'm not a js/ts dev 😁 -
dder22814yLacking background knowledge, how do you want to represent an event as a Promise ? There is basically no difference to use a promise or callbacks. It’s just syntactic sugar IMO.
-
@dder The difference is in semantics. Promises can reject anytime for any reason. If a callback has no "error" argument you know there's nothing to handle. At the same time, promises can only be resolved once, for a callback that isn't a given. However, one might assume that a promise will resolve or reject at some point, whereas in my case that can't be known.
Additionally, with promises I have much less control over references so it's harder to let the user cancel the request and ensure that the handler gets GCd.
Related Rants
[typescript] Should I use a promise to represent an event that can occur at most once, may never occur but can never fail? If not, what else should I use? Callbacks?
question
callback
promise
event
typescript