the document said:
- Visibility
private
restricts access to<id>
to the enclosing object, module or actor.- Visibility
public
extendsprivate
with external access to<id>
using the dot notation<exp>.<id>
.
as I test in:
actor Main {
var a = 1;
var b = 1;
var c = 1;
public func add1() {
c := a + b;
};
public func addx() : async () {
c := a + b;
};
private func add2() : Nat {
c := a + b;
return c;
};
public func add3() : async Nat {
c := a + b;
return c;
};
private func add4() : async Nat {
c := a + b;
return c;
};
public func add5() : async Nat {
add1();
return c;
};
public func add6() : async Nat {
ignore add3();
return c;
};
public func add7() : async Nat {
ignore await add3();
return c;
};
public func reset() : async Nat {
c := 1;
return c;
};
public query func geta() : async Nat {
return a;
};
public query func getb() : async Nat {
return b;
};
public query func getc() : async Nat {
return c;
};
};
code above is compiled successful.
the candid file is:
candid
service : {
add1: () -> () oneway;
add3: () -> (nat);
add5: () -> (nat);
add6: () -> (nat);
add7: () -> (nat);
addx: () -> ();
geta: () -> (nat) query;
getb: () -> (nat) query;
getc: () -> (nat) query;
reset: () -> (nat);
}
In the actor, are the following conclusions correct:
- Although add1 does not have async, it is also “export” and publicly available, just like addx. But add1 and addx are not exactly the same, because there is oneway more in add1 in candid. Can someone explain what oneway means?
- Although add4 has async, it is private and invisible to the outside wasm/canister. In this case, why not restrict private functions from being modified with async?
- add5 calls add1 without using asynchronous
- add6 calls add3 without using asynchronous, although add3 is decorated with async. When a function in the canister calls others functions, even if which is an asynchronous function, it can be called synchronously.
- add7 calls add3 with using asynchronous