Let’s say that I want a function that makes an async call and returns a future (that can be awaited upon.
type LedgerActor = actor {
icrc1_balance_of : ({owner: Principal; subaccount: ?Blob}) -> async Nat;
};
func makeBalanceOfFuture(ledgerActor: LedgerActor, owner : Principal) : async Nat {
ledgerActor.icrc1_balance_of({ owner; subaccount = null });
};
I’d like to be able to do this, but the compiler yells:
expression of type
async<$makeBalanceOfFuture> Nat
cannot produce expected type
Nat (M0096)
Using async<$makeBalanceOfFuture> Nat
isn’t supported
// Not supported
func makeBalanceOfFuture(ledgerActor: LedgerActor, owner : Principal) : async<$makeBalanceOfFuture> Nat
I tried a number of approaches to what the type of $makeBalanceOfFuture
could be, but gave up and figured it would be easier to just ask in the forums.
Is it possible in Motoko to achieve what I’m trying to do here?