Last active
February 13, 2020 21:37
-
-
Save pchiusano/52f75f9a64c3460db74addced0abbf8e to your computer and use it in GitHub Desktop.
Async ability in Unison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Nat is just an index into some internal store | |
-- provided by the handler | |
unique type Source a = Source Nat | |
unique type Sink a = Sink Nat | |
ability Abort where abort : a | |
-- You wouldn't typically program with these operations directly, | |
-- but you can implement `fork` in terms of these operations | |
ability Async where | |
promise : Either (Sink a) (Source a) | |
wait : Source a -> a | |
complete : a -> Sink a -> x | |
fork : '{e} a ->{Async,e} '{Async} a | |
fork a = match Async.promise with | |
Left sink -> complete !a sink | |
Right src -> '(wait src) | |
-- we also considered - | |
ability Async where | |
promise : Either (Sink a) (Source a) | |
wait : Source a -> a | |
complete : a -> Sink a -> () | |
fork : '{e} a ->{Async,e} '{Async,Abort} a | |
fork a = match Async.promise with | |
Left sink -> | |
complete !a sink | |
'Abort.abort | |
Right src -> '(wait src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit: @dolio in Unison Slack.