Semicoroutines.jl

C# style generators a.k.a. semi-coroutines for Julia. Fork of Ben Lauwens' ResumablFunctions.jl
Author QuantumSavory
Popularity
7 Stars
Updated Last
1 Year Ago
Started In
April 2023

A shortlived fork of ResumableFunctions -- all changes are now upstreamed to the original and the original is now actively maintained once more.

Semicoroutines

Documentation Documentation of latest stable version Documentation of dev version
Continuous integration GitHub Workflow Status
Code coverage Test coverage from codecov
Static analysis with JET static analysis Aqua QA

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

Caveats

  • 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.

Required Packages

Used By Packages

No packages found.