Top Level Namespace
Defined in:
Method Summary
-
delay(delay, &block : -> _)
Spawns a
Fiber
to compute &block in the background after delay has elapsed. -
future(&exp : -> _)
Spawns a
Fiber
to compute &block in the background. -
lazy(&block : -> _)
Conditionally spawns a
Fiber
to run &block in the background.
Method Detail
Spawns a Fiber
to compute &block in the background after delay has elapsed.
Access to get
is synchronized between fibers, and returns the block value
after the &block completes. &block is only called once.
get
may be called multiple times, and returns the block's return value or
re-raises any unrescued Exception.
May be canceled before &block is called by calling cancel
.
Calling get
before the delay has elapsed results in the call waiting for the delay
to fully elapse and compute to next finish, then the value is returned.
d = delay(1) { Process.signal(Signal::KILL, Process.pid) }
# ... long operations ...
d.cancel
Spawns a Fiber
to compute &block in the background.
Access to get
is synchronized between fibers, and returns the block value
after the &block completes. &block is only called once.
get
may be called multiple times, and returns the block's return value or
re-raises any unrescued Exception.
f = future { `echo hello` }
# ... other actions ...
f.get # => "hello\n"
Conditionally spawns a Fiber
to run &block in the background.
Access to get
is synchronized between fibers, and returns the block value
after the &block completes. &block is only called once.
get
may be called multiple times, and returns the block's return value or
re-raises any unrescued Exception.
&block doesn't run by default, only when get
is called.
l = lazy { expensive_computation }
spawn { maybe_use_computation(l) }
spawn { maybe_use_computation(l) }