This repo is branched from https://github.com/durcan/Select.jl, which was originally a copy of Jon Malmaud's go-inspired select macro for the Julia programming language. I have updated the repo for Julia 1.3+, multithreaded the Select macro, and hardened the code a bit.
Install this package via:
The original README from durcan/Select.jl follows:
This is copy of Jon Malmaud's go inspired select macro for the Julia programming language. I have made a slight syntax modification, but essentially all the code is his.
A select expression is for waiting on multiple communication operations and is of the form:
@select begin clause1 => body1 clause2 => body2 _ => default_body end end
Wait for multiple clauses simultaneously using an pattern matching syntax, taking a different action depending on which clause is available first. A clause has three possible forms:
event |> valueIf
AbstractChannel, wait for a value to become available in the channel and assign
Task, wait for the task to complete and assign
valuethe return value of the task.
event |< valueOnly suppored for
AbstractChannels. Wait for the channel to capabity to store an element, and then call
event, discarding the return value. Usable on any "waitable" events", which include channels, tasks,
Conditionobjects, and processes.
If a default branch is provided,
@select will check arbitrary choose any event which is ready and execute its body, or will execute
default_body if none of them are.
@select blocks until at least one event is ready.
channel1 = Channel() channel2 = Channel() task = @task ... result = @select begin channel1 |> value => begin info("Took from channel1") value end channel2 <| :test => info("Put :test into channel2") task => info("task finished") end