forked from jl777/SuperNET
-
Notifications
You must be signed in to change notification settings - Fork 116
Closed
Description
I've been wanting for a repeatable futures for a long time, and I guess I got a solution using a macro.
Let's see an example:
https://github.com/KomodoPlatform/atomicDEX-API/blob/dff315f90c1ede37e5ccfcc5dec9018f6dd40b82/mm2src/coins/utxo/utxo_builder/utxo_coin_builder.rs#L820-L841
The main idea is to capture the code of the async block and return it from an Fn closure:
https://github.com/KomodoPlatform/atomicDEX-API/blob/dff315f90c1ede37e5ccfcc5dec9018f6dd40b82/mm2src/common/patterns/repeatable.rs#L14-L16
Currently, I added support for the future attempts, but I'm looking forward to continue the implementation, for example, repeat-until feature:
repeatable!(async {
match rpc_client.version().await {
Ok(version) => ready!(version),
Err(_) => retry!(),
}
})
.repeat_until(now_ms() + 1000 * 10) // Repeat until now + 10 seconds.
. await;Current implementation is available here
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels