protoflow_core/
block_runtime.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// This is free and unencumbered software released into the public domain.

use crate::{
    prelude::{Duration, Instant, Range},
    BlockError, Port,
};

pub trait BlockRuntime: Send + Sync {
    fn is_alive(&self) -> bool;

    fn sleep_for(&self, duration: Duration) -> Result<(), BlockError>;

    fn sleep_until(&self, instant: Instant) -> Result<(), BlockError>; // TODO

    /// Wait for a port to be connected.
    fn wait_for(&self, port: &dyn Port) -> Result<(), BlockError>;

    fn yield_now(&self) -> Result<(), BlockError>;

    fn random_duration(&self, range: Range<Duration>) -> Duration;
}