Can an async frame be copied and resumed multiple times?

Basically the title. I’m interested in knowing whether a function can be duplicated this way.

This minimal example doesn’t crash:

fn fun() void {
    suspend {}
    suspend {}
}

test {
    var frame = async fun();

    var frame_copy = frame;

    resume frame;
    resume frame;
    resume frame_copy;
    resume frame_copy;
}

But will it always work?

A frame can (and should) be resumed a number of times corresponding to the number of times is suspends. Resume and suspend must be “in sync”.

I think copying frames is UB but I’m not 100% sure about the specific rules about it. Now that we’re adding async/await back into the compiler I will probably have a chance to dust off my knowledge of it.

Lastly, be aware that suspend and resume are low level APIs, so if you’re not making an event loop (or something similar), you should most probably only need async and await.

I’ll err on the safe side and stick to one resumption per suspension then, thanks.

I’m (ab)using suspend/resume to implement continuations ;)

Ciao da Pisa! Sad I missed the pisa.dev event :no_mouth:

1 Like

Ciao da Pisa! Sad I missed the pisa.dev event :no_mouth:

It’s on the 20th, so you still have a couple of days if you want to come :^)

Me getting lost in the calendar again :+1:
Thanks for the heads up!