Motoko equivalent of C# Task.Delay()

Is this complete Time | Internet Computer Home

I don’t think the timers api has been released to motoko yet. You can keep up with updates at Heartbeat improvements / Timers [Community Consideration]

1 Like

Thanks for the link :slightly_smiling_face:

skimming over

didn’t see anything on timers, sleep or delay :slightly_frowning_face:

in my case I guess I can just query an external canister for a short delay

That’s not a bad idea, but you currently can’t make inter-canister query calls, only inter-canister update calls are supported.

Also, keep in mind that while an inter-canister update call is in-flight it might be blocking other update messages from being processed, so you may not get the behavior you’re looking for.

It might be helpful if you provide an MVP of the “delay” functionality that you’re looking for in the context of a use case, or a code sample (maybe on the Motoko Playground).

1 Like

this seems to be working for me

let external_canister = actor "canister_id" : actor {
        get_location: query () -> async { x : Int; y : Int };
    };

having a convenient delay function is great for prototyping anything async

currently using

let raw_rand = (actor "aaaaa-aa" : actor { raw_rand : () -> async Blob }).raw_rand;
for (_ in Iter.range(0, count))
  ignore await raw_rand();

any ideas on how to use
Timer.setTimer
instead :thinking:

while keeping the same local scope like above