“Concurrency made easy”: coming soon to a programming language near you

Structured concurrency

try:
async with open_nursery() as nursery:
nursery.start_task(a)
nursery.start_task(b)
nursery.start_task(c)
# end of nursery scope
# at this point tasks a, b, and c must be completed
...
except FooError: # e.g. some exception raised by task "b"
...

Concurrency honoring imperative constructs

do_request(url) {
request(url, (err, res, body) => {
if (err) { // sorry, can't use try/catch!
...
} else {
let body = JSON.parse(body).value;
if (some_condition) return null; // not what you think!
...
}
}
}
async do_request(url) {
try {
let body = await request(url);
body = JSON.parse(body).value;
if (some_condition) return null;
...
} catch (err) {
...
}
}

Explicit, cooperative multitasking

async def foo(self):
await a()
self.balance += 100 # modify shared state
self.b() # modify even more shared state
await self.c()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store