task - pannous/warp GitHub Wiki
A task object holds the state of async function calls. Very similar to c# and java threads, slightly similar to javascripts broken promises.
download(url) := { sleep 100ms; url }
job = go download("https://example.com")
job.stop
Tasks created with the go keywords are automatically started by default.
await job waits for its value; a task can also stop, pause, cancel, resume and finish.
go xs.map(f) maps in a task: xs = go [1, 2, 3].map(x => x * 2); await xs is [2 4 6].
Two calls that do not depend on each other run at once with the parallel let, a b = f(x) g(y), written without let (thread).
A task is typed and from the developers perspective acts just as its type when passed as argument or when assigned:
# … stands for the rest
content = go download url
content2 = go download url2
print parse content
...
what happens under the hood is that the execution of parse and print is delayed until the download finished. It is however NOT delayed by the second download.
Todo: what to do if the type contains functions or properties conflicting with the chimeric task object, such as stop pause etc. At the minimum a compiler warning: "please disambiguate..."