I have in DBPartition.mo
:
public shared({caller = caller}) func delete(options: CanDB.DeleteOptions) {
if (checkCaller(caller)) {
CanDB.delete(db, options);
};
};
In main.mo
it is called like:
var db: DBPartition.DBPartition = actor(Principal.toText(paymentCanisterId));
db.delete({sk = "p/" # Principal.toText(userId)}); // FIXME: `await`?
I wonder how an inter-canister call db.delete
works without await
(and even does not compile if I add await
).
func delete
looks like a synchronous call because I didn’t added result type async ()
, but isn’t it (as a shared function) async by default?
As I understand, inter-canister calls are always asynchronous.
I do not understand something.
timo
May 14, 2023, 5:45am
2
It is a “one-way call” that has no response and can’t be awaited.
The implicit return type when no return type is given is ()
. These are equivalent:
public func f() { ... };
public func f() () { ... };
But ()
is different from async ()
. The latter creates an empty response which can be awaited. The former doesn’t create a response and cannot be awaited. Those are called one-way calls.
A public function can have return type ()
or async X
, nothing else.
1 Like
You probably meant:
public func f() { ... };
public func f() : () { ... };
icme
May 14, 2023, 10:10pm
4
CanDB’s delete API is synchronous (within a single canister) and does not involve any inter-canister calls.
https://www.candb.canscale.dev/CanDB.html#delete
}
}
}
};
public type DeleteOptions = {
sk: E.SK;
};
/// Removes an entity from the DB if exists
public func delete(db: DB, options: DeleteOptions): () {
ignore remove(db, options);
};
public type RemoveOptions = DeleteOptions;
/// Remove an entity from the DB and return that entity if exists
public func remove(db: DB, options: RemoveOptions): ?E.Entity {
let removedAttributeMap = RT.remove(db.data, options.sk);
switch(removedAttributeMap) {
case null { null };