Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Last active February 2, 2025 18:01
// Let's say we have a block of code (boc) called `counter` with a variable `value`
counter : {
value: 0
// `inc` is an internal boc, and has access to outer scope
inc: { value = value + 1 }
}
// Two other bocs `foo` and `bar` could read `counter.value` but can't write to it.
// Only the original boc `counter` can (or inner bocs)
foo: {
counter.value // do something with value
// counter.value = 1 would be a compilation error
counter.inc()
}
bar: {
counter.value
counter.inc()
}
//When `foo` and `bar` execute, the'll run concurrently and they will call counter.inc()
// The boc `counter` will be the only writer and will execute `inc` sequentially behaving like
// (think of Actors / Redis )
main: {
foo()
bar()
// foo and bar execute concurrently, think of Go's `go foo(); go bar()`
// and synchronize at this point
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment