Skip to content

Carlyle-Foster/coro

 
 

Repository files navigation

coro: coroutines for odin

Create! your coroutine

package my_coroutine

import co "path/to/coro"

import "core:fmt"

message := "this is.."

main :: proc() {
    c := co.create(proc(cc: co.Caller) {
        for _ in 0..<2 {
            fmt.println(message)
            co.pass(cc)
        }
    })

Resume it

co.resume(&c)
This is..

Resume it again!

message = "..a test"
co.resume(&c)
..a test

A resounding success

// resume returns false when the coroutines done
assert(co.resume(&c) == false)

fmt.println("A resounding success")
A resounding success

Now put it all together

package my_coroutine

import co "path/to/coro"

import "core:fmt"

message := "this is.."

main :: proc() {
    c := co.create(proc(cc: co.Caller) {
        for _ in 0..<2 {
            fmt.println(message)
            co.pass(cc)
        }
    })
    co.resume(&c)
    message = "..a test"
    co.resume(&c)

    // resume returns false when the coroutines done
    assert(co.resume(&c) == false)

    fmt.println("A resounding success")
}
This is..
..a test
A resounding success

Installation

cd your-project
git clone https://github.com/Carlyle-Foster/coro.git
import co "coro"

thank u to tsoding's C coroutine library, our distant ancestor.
the ship of theseus has sailed indeed...

About

coroutines for odin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Odin 73.3%
  • Assembly 23.4%
  • Python 3.3%