Skip to content

Consider adding repeatable future PoC #1558

@sergeyboyko0791

Description

@sergeyboyko0791

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions