Real-Serious-Games / C-Sharp-Promise

Promises library for C# for management of asynchronous operations.
MIT License
1.19k stars 149 forks source link

"Resolve" a promise multiple times #69

Closed nah0y closed 6 years ago

nah0y commented 6 years ago

Hello again,

Is there to "resolve" a promise multiple times? Imagine I'm scanning for bluetooth devices, and I use a Promise for that. I would like to call .Resolve(deviceAddress) every time a new address is found for example, and start another process that will reject the promise after 60sc (to stop scanning). I don't think there's a way to do that, right?

sindrijo commented 6 years ago

Is there to "resolve" a promise multiple times?

No, that kind of goes against the idea of a Promise, you should be using an event/callback or message pattern.

A promise: Try to do this for me, and then tell me when you've succeeded or failed. An event: Tell me whenever this happens, so I can react to it.

ashleydavis commented 6 years ago

You should be using reactive extensions for that (rx), that's an implementation of asynchronous streaming.

Where a promise is an asynchronous delivery mechanism for a single result, rx is an asynchronous delivery mechanism for a continuous stream of results.

I recommend reading the book into to rx, is free online.

nah0y commented 6 years ago

Thanks to both of you for your answers. That's what I thought (and I'm currently using event/callbacks), but thanks for the tip with rx!

ashleydavis commented 6 years ago

Here's a link to the book: http://www.introtorx.com/

If you like it please buy it to support the author.

Also more generally you should google 'reactive programming'. It's a really interesting concept that a lot of people are experimenting with.

nah0y commented 6 years ago

Yes, I see that a lot recently. I have to find some time to dig into it though :(