Early preview: syntax, standard library APIs, and tooling may change.

Safety and Runtime ModelConcurrency

Concurrency

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

Concurrent:

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

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

Task Results

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

match left:
    Ok(value): print(value)
    Err(_): print_error("task failed")

Timeouts

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

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

Cancellation Points

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

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) -- prints: 42
			0
		_:
			print_error("task failed")
			1

Try it

terminal
blorp run two-tasks.brp