Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

C# style generators a.k.a. semi-coroutines for Julia. Fork of Ben Lauwens' ResumablFunctions.jl

License

Notifications You must be signed in to change notification settings

QuantumSavory/Semicoroutines.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Languages

  • Julia 100.0%