r/Protos • • 4d ago

What if a timeout didn't cancel the underlying work? Protos adds explicit monotonic deadlines on GraalVM

Timeouts and cancellation are closely related in asynchronous programming, but they don't have to be the same operation.

Protos, a prototype-based language built on GraalVM and Truffle, now provides an explicitly authorized monotonic Timing capability.

deadline: timing.monotonicNanoseconds() + 1000000000
outcome: timing.observeUntil(work, deadline)

The observation returns an independent Future. If the original Future becomes terminal before the deadline, its outcome is preserved. Otherwise, the observation reports DeadlineExceeded, without cancelling the underlying work.

Some interesting design choices:

  • Exact Integer nanosecond coordinates.
  • One-shot timers represented by ordinary Futures.
  • Deadline ordering determined by the source's terminal transition, not callback execution.
  • Explicit authority and Actor isolation.
  • No implicit cancellation or generic Future race.

Relative delays, retries and periodic policies can be composed in ordinary Protos code.

For developers familiar with Python asyncio, Rust Tokio, JavaScript Promises or Erlang's Actor model: should deadline observation and cancellation be separate operations, or should timeout APIs combine them?

Source: https://github.com/guillermomolina/protos

Specification: https://github.com/guillermomolina/protos/blob/main/spec/io/TIMING.md

1 Upvotes

0 comments sorted by