JuliaDynamics / ResumableFunctions.jl

C# style generators a.k.a. semi-coroutines for Julia.
Other
158 stars 19 forks source link

Doesn't work in file I/O do-blocks #28

Closed Malthanatos closed 5 years ago

Malthanatos commented 5 years ago

Using Julia 1.0.0 and ResumablePackages 0.4.1

I can get around it by simply doing non-block based I/O lines so it isn't a huge deal, but the below block of code gives the following error:

using ResumableFunctions

@resumable function f(file::String)
    open(file, "r") do io              # works if you instead use: io = open(file,"r")
        lines = readlines(io)
        for line in lines
            @yield line
        end
    end                                # and replace this with: close(io)
end;

for line in f("test.txt")
    println(line)
end

ERROR: LoadError: syntax: label "_STATE_1" referenced but not defined Stacktrace: [1] include at .\boot.jl:317 [inlined] [2] include_relative(::Module, ::String) at .\loading.jl:1038 [3] include(::Module, ::String) at .\sysimg.jl:29 [4] exec_options(::Base.JLOptions) at .\client.jl:229 [5] _start() at .\client.jl:421 in expression starting at C:\...\file.jl:3

BenLauwens commented 5 years ago

Hi

a do block is an anonymous function in disguise and we can not do "@goto" into another function. So this can not be fixed. Sorry for the late response! Kind regards

Ben