Motoko: Interesting one shot behavior

That’s not a one way/fire-and-forget function.

Only a shared function with implicit or explicit return type () (never async ()) is one way.

If you call, but don’t await the result, it will also complete asynchrously, but isn’t as safe for upgrades.

However, I’m still a little puzzled by that behaviour myself. What is the body of func_x?

For example, I’m not seeing this behaviour in this program:

Motoko Playground - DFINITY

actor {
  var log : Text = "";

  func do_something_1 () {
    log #= "something_1;";
  };

  func do_something_2 () {
    log #= "something_2;";
  };


  func func_x(t : Text) : async () {
    log #= t # ";";
  };

  public shared func test () : async Text {
    log := "";
    do_something_1();

    try {
      let future = await func_x("test");
    } catch(err){};

    do_something_2();
    log;
  } 

}

Calling test() returns:

("something_1;test;something_2;")
2 Likes