[][src]Function kwait::wait_for

pub fn wait_for<F>(
    wait: Box<dyn Fn(Receiver<bool>) -> Receiver<bool>>,
    func: F,
    done: Receiver<bool>
) -> Result<(), Box<dyn Error>> where
    F: Fn() -> Result<bool, Box<dyn Error>> + Copy

wait_for continually checks 'fn' as driven by 'wait'.

wait_for gets a channel from 'wait()', and then invokes 'fn' once for every value placed on the channel and once more when the channel is closed. If the channel is closed and 'fn' returns false without error, wait_for returns WaitTimeoutError.

If 'fn' returns an error the loop ends and that error is returned. If 'fn' returns true the loop ends and nil is returned.

WaitTimeoutError will be returned if the 'done' channel is closed without fn ever returning true.

When the done channel is closed, because the golang select statement is "uniform pseudo-random", the fn might still run one or multiple time, though eventually wait_for will return.