Safety and Runtime ModelConcurrency
Blorp by Example

Concurrency

concurrent: starts child work and joins it before control continues.

Concurrent:

Each binding inside a concurrent: block runs as a child task.

concurrent.brp
concurrent:
    left = slow_left()
    right = slow_right()

Task Results

After the block, each binding is Result[T, ConcurrencyError].

task-result.brp
match left:
    Ok(value): print(value.to_string())
    Err(_): eprintln("task failed")

Timeouts

concurrent(timeout: N) cancels work that has not completed before the timeout.

timeout.brp
concurrent(timeout: 500):
    value = slow_operation()

Cancellation Points

Cancellation is cooperative at sleep, channel send/recv, and task joins.

cancel.brp
func slow() -> Int:
    sleep(100)
    42

Example

two-tasks.brp
func slow_left() -> Int:
	sleep(100)
	20


func slow_right() -> Int:
	sleep(100)
	22


func main(args: List[String]) -> Int:
	concurrent(timeout: 500):
		left = slow_left()
		right = slow_right()

	match (left, right):
		(Ok(a), Ok(b)):
			print((a + b).to_string())
			0
		_:
			eprintln("task failed")
			1

Try It

terminal
blorp run two-tasks.brp