grantila / q

A platform-independent promise library for C++, implementing asynchronous continuations.
http://libq.io
Apache License 2.0
192 stars 24 forks source link

Creating a timeout for a promise #29

Open deblauwetom opened 5 years ago

deblauwetom commented 5 years ago

Hello,

I'm trying to use libq to create a timeout for a function that may take too long to complete. So the case is that if the function completes in time, say 5 seconds, it's ok, otherwise I want the promise to be rejected. So I created a shared promise, with one branch running the function, and another running a .delay(5s).then(...). But now I want to "cancel" the delay task if my function was completed within 5s. What would be the preferred way for this?

Best regards, Tom,