ResumableFunctions @yield doesn't work even in the simplest IO example

This is the simplest IO example (copied from AI) and explicitly supported in the docs:

@resumable function read_lines(filename)
    io = open(filename)
    try
        for line in eachline(io)
            @yield line
        end
    finally
        close(io)
    end
end

Documentation (GitHub - JuliaDynamics/ResumableFunctions.jl: C# style generators a.k.a. semi-coroutines for Julia. · GitHub) says: " * In a try block only top level @yield statements are allowed."

Error I get: ERROR: LoadError: syntax: cannot goto label “_STATE_1” inside try/catch block

I guess this might be expected since we have a loop, but that makes ResumableFunctions practically useless for IO iterators.
Anybody has a better idea?

You can create a struct and implement the iteration interface. Interfaces · The Julia Language

I don’t see an example with open or try-finally in the docs, so it’s not explicitly supported. “Top level” in the caveat means that you can’t have any local scope-introducing blocks, like for loops, so I’d be surprised if it were. open(...) do ... won’t work because anonymous functions are explicitly unsupported. I don’t see an explicit mention in the other caveats, but it doesn’t do named nested functions or closures either.

The goal is to automatically generate a state machine from a function definition block with an intuitive loop structure. A scheduled Task put!-ing objects into a Channel does that, but the scheduling is unnecessary overhead for iteration. Even if you’re willing to write out iterate, it’s not trivial in general to describe and maintain the stack frame in a struct. ResumableFunctions only went so far.