MyNixOS website logo
Description

Pure deterministic scheduled computations.

Schedule computations to run later, in a pure and deterministic way.

This library is a pure alternative to System.Timeout suitable for IO-bound non-blocking computations. System.Timeout has a few issues that are at-odds with a Haskell or purely functional paradigm: (1) it is not deterministic, (2) the timeout state is not serialisable, and (3) the timeout functionality must be shared between unrelated components, making it harder to design components that are easily decomposable and reusable.

This library solves these issues by implementing all schedule and timeout logic as a pure deterministic computation, with callbacks represented in defunctionalised serialisable form. The interface with the runtime execution environment is minimal: a simple source of clock inputs similar to other inputs such as network traffic or user commands, which can either be an IO-based impure "real" runtime, or a pure "mock" one e.g. that replays previous inputs to reproduce previous outputs.

This library does no pre-emption e.g. by sending interrupts or asynchronous exceptions, so it is probably not suitable for blocking computations. To be clear, things will work, but clock inputs will be delivered only after the blocking is over. A workaround is to separate the blocking computations from your main computation, arrange to have these run externally (e.g. in worker threads) with the results being sent back to your main computation via some pure abstract input interface, similar to how we deliver clock inputs.

If this is not suitable and you absolutely need pre-emption, then you'll need a richer runtime interface than the one expected by this library; luckily the Haskell runtime itself is such an example. In other words, simply use other existing IO-based utilities for setting timeouts, that typically rely on concurrency or asynchronous exceptions. But then, you'll have to figure out your own way of overcoming the issues mentioned in the first paragraph.

The original motivation for this library comes from implementing secure communications protocols and decentralised distributed systems. In these contexts one must often set local timeouts for remote events that may or may not happen in the future, or periodically synchronise local views of shared data with remote peers. Most operations are IO-bound and can be written to be non-blocking; the main exception is heavy cryptography which can be delegated to worker threads as described above. Of course, this library is not tied to these use-cases and is a general replacement for System.Timeout.

See Control.Monad.Schedule for the main monad-based API of this library.

See Control.Arrow.Schedule for the main arrow-based API of this library.

See Control.Clock.IO for various ways of combining clock inputs with other inputs and injecting them into your pure computations.

See Control.Schedule.* for higher-level utilities that one often wants to use on top of a timeout primitive, such as futures and monitors.

See unit tests for example usage.

Metadata

Version

0.3.0.0

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows