A shortlived fork of ResumableFunctions -- all changes are now upstreamed to the original and the original is now actively maintained once more.
Documentation | |
Continuous integration | |
Code coverage | |
Static analysis with |
C# has a convenient way to create iterators using the yield return
statement. The package Semicoroutines
provides the same functionality for the Julia language by introducing the @resumable
and the @yield
macros. These macros can be used to replace the Task
switching functions produce
and consume
which were deprecated in Julia v0.6. Channels
are the preferred way for inter-task communication in julia v0.6+, but their performance is subpar for iterator applications. See the benchmarks section below.
Semicoroutines.jl
is a fork Ben Lauwens' of ResumableFunctions.jl
.
using Semicoroutines
@resumable function fibonacci(n::Int) :: Int
a = 0
b = 1
for i in 1:n
@yield a
a, b = b, a+b
end
end
for fib in fibonacci(10)
println(fib)
end
- In a
try
block only top level@yield
statements are allowed. - In a
finally
block a@yield
statement is not allowed. - An anonymous function can not contain a
@yield
statement.