within takes a Duration
🤖 Generated with [ECA](https://eca.dev) (anthropic/claude-opus-5-5) Co-Authored-By: eca-agent <git@eca.dev>
This commit is contained in:
parent
4ec7d300c9
commit
c9486122fe
1 changed files with 6 additions and 6 deletions
12
index.sz
12
index.sz
|
|
@ -39,14 +39,14 @@ build it.
|
||||||
ConcurrentML brings the multithreading story for bjolang into the 1990s. It uses events that can be combined and synced on, meaning you can build trees of events and then preform them. This is indeed an extra layer for most operations in cml compared to CSP-inspired things, but allows us to write composable events. The function @code{within} returns a new event can be composed with other events. You can of course perform @code{within} in golang by writing a special function that races two fibers, but the composable version is not writeable.
|
ConcurrentML brings the multithreading story for bjolang into the 1990s. It uses events that can be combined and synced on, meaning you can build trees of events and then preform them. This is indeed an extra layer for most operations in cml compared to CSP-inspired things, but allows us to write composable events. The function @code{within} returns a new event can be composed with other events. You can of course perform @code{within} in golang by writing a special function that races two fibers, but the composable version is not writeable.
|
||||||
|
|
||||||
@codeblock[#:lang "bjolang"]{
|
@codeblock[#:lang "bjolang"]{
|
||||||
(: within (-> int (Event %a) (Event (Option %a))))
|
(: within (-> Duration (Event %a) (Event (Option %a))))
|
||||||
(defun (within ms ev)
|
(defun (within d ev)
|
||||||
(choose (wrap ev #(Some &))
|
(choose (wrap ev #(Some &))
|
||||||
(wrap (timeout ms) (fun (u) None))))
|
(wrap (timeout d) (fun (u) None))))
|
||||||
|
|
||||||
(sync (within 20 (chan-recv kitchen))) ;; => None, and nothing is consumed
|
(sync (within (milliseconds 20) (chan-recv kitchen))) ;; => None, and nothing is consumed
|
||||||
(sync (within 500 (chan-recv kitchen))) ;; => (Some "dinner")
|
(sync (within (milliseconds 500) (chan-recv kitchen))) ;; => (Some "dinner")
|
||||||
(sync (within 20 (spawn-evt (count-to 1000)))) ;; works on fibers too
|
(sync (within (milliseconds 20) (spawn-evt (count-to 1000)))) ;; works on fibers too
|
||||||
}
|
}
|
||||||
|
|
||||||
This sums every line and every char read from stdin. When the port is closed, the result is printed using the show function from (std fmt).
|
This sums every line and every char read from stdin. When the port is closed, the result is printed using the show function from (std fmt).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue