Lyricdev
GitHub

LYR-RT0014

a coroutine misused

panic · spec 10-concurrency

A coroutine is used against its rules: a yield where no coroutine runs, or in a task outside every generator; a coroutine resumed while it runs, after it ended, or on another thread; a coroutine closed while it runs or is parked, or with C frames on its stack — a callback that yielded in it; a yield of another type than the running generator's.

Program

import std.task { Cancelled };

fn emit(): void throws Cancelled {
    yield 1;
}

fn main(): void {
    try {
        emit();
    } catch (_: Cancelled) {
    }
}