This commit is contained in:
Loic Nageleisen 2015-12-15 13:50:47 +01:00
parent 0cdf0a490a
commit 06273c3525
11 changed files with 208 additions and 29 deletions

15
lib/channel/runtime.rb Normal file
View file

@ -0,0 +1,15 @@
require 'thread'
module Channel::Runtime
module_function
def go(prc, *args)
Thread.new { prc.call(*args) }
end
end
module Kernel
def go(prc, *args)
Channel::Runtime.go(prc, *args)
end
end

17
lib/channel/timer.rb Normal file
View file

@ -0,0 +1,17 @@
class Channel::Timer
attr_reader :channel
def initialize(delay)
@channel = Channel.new(1)
@prc = -> { sleep delay; channel << Time.now }
start
end
def start
Channel::Runtime.go @prc
end
def self.after(delay)
new(delay).channel
end
end