Extern callback to async/await?

I’m a bit puzzled here because what magic is happening in frame.* = async ... is it seeing that and creating that frame inside memory I allocated? it felt like it was normally this syntax would be used as to set the value of a pointer, making it a copy

watching this video, it says you can’t suspend a frame twice…

but if resumed the copy of a frame how will the compiler know that?

const allocator = @import("std").heap.page_allocator;
const print = @import("std").debug.print;

fn foo() void {
  suspend {}
  print("hello\n", .{});
}

pub fn main () !void {
   const frame1 = allocator.create(@Frame(foo)) catch unreachable;
   const frame2 = allocator.create(@Frame(foo)) catch unreachable;

  frame1.* = async foo();

  frame2.* = frame1.*;
  resume frame1; //1
  resume frame2; //2
}

whats the output does it compile? bets everyone!

hello
hello

yes it resumes twice!

so in conclusion… the value of async foo() is dropped off the stack when the main function returns, but since I cloned it, it can resume more than once.

but that must mean that the first frame is also valid?

   const frame1 = allocator.create(@Frame(foo)) catch unreachable;
   const frame2 = allocator.create(@Frame(foo)) catch unreachable;

  var frame = async foo(); //on the stack
  frame1.* = frame; //heap1
  frame2.* = frame; //heap2
  resume frame1; //1
  resume frame2; //2
  resume frame;  //3

and yes it outputs hello\n 3 times.