def timeout
import bend-kit-concurrency@0.2.0.0/concurrency.bend as Concurrencyimport Base
334# Some{result} if act finishes within ms milliseconds, else None at the
335# deadline. act is not cancelled: it runs on, its late result is dropped, and
336# the program waits for it (and for the timer) before it exits.
337def timeout(-A: Type, ms: U32, act: IO(A)) -> IO(Maybe<&1, A>):
338 do IO<Maybe<&1, A>>:
339 chan : Chan(Maybe<&1, A>) <- Chan.new(Maybe<&1, A>, 0)
340 +c : Chan(Maybe<&1, A>) = chan
341 IO.spawn(Result<&1, &1, Maybe<&1, A>, Unit>, IO.bind(A, Result<&1, &1, Maybe<&1, A>, Unit>, act, x => Chan.send(Maybe<&1, A>, c, Some{x})))
342 IO.spawn(Result<&1, &1, Maybe<&1, A>, Unit>, IO.bind(Unit, Result<&1, &1, Maybe<&1, A>, Unit>, IO.sleep(ms), u => Chan.send(Maybe<&1, A>, c, None{})))
343 got : Maybe<&1, Maybe<&1, A>> <- Chan.recv(Maybe<&1, A>, c)
344 timeout.won(A, c, got)
Uses (13)
Used by (0)
No other definition uses this definition.