Class: Async::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/async/scheduler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reactor) ⇒ Scheduler

Returns a new instance of Scheduler.


35
36
37
# File 'lib/async/scheduler.rb', line 35

def initialize(reactor)
	@reactor = reactor
end

Instance Attribute Details

#wrappersObject (readonly)

Returns the value of attribute wrappers


39
40
41
# File 'lib/async/scheduler.rb', line 39

def wrappers
  @wrappers
end

Class Method Details

.supported?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'lib/async/scheduler.rb', line 26

def self.supported?
	true
end

Instance Method Details

#block(blocker, timeout) ⇒ Object


91
92
93
# File 'lib/async/scheduler.rb', line 91

def block(blocker, timeout)
	@reactor.block(blocker, timeout)
end

#clear!Object


45
46
47
# File 'lib/async/scheduler.rb', line 45

def clear!
	Fiber.set_scheduler(nil)
end

#closeObject


99
100
# File 'lib/async/scheduler.rb', line 99

def close
end

#fiber(&block) ⇒ Object


102
103
104
105
106
107
108
109
110
# File 'lib/async/scheduler.rb', line 102

def fiber(&block)
	task = Task.new(@reactor, &block)
	
	fiber = task.fiber
	
	task.run
	
	return fiber
end

#io_wait(io, events, timeout = nil) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/async/scheduler.rb', line 53

def io_wait(io, events, timeout = nil)
	wrapper = from_io(io)
	
	if events == ::IO::READABLE
		if wrapper.wait_readable(timeout)
			return ::IO::READABLE
		end
	elsif events == ::IO::WRITABLE
		if wrapper.wait_writable(timeout)
			return ::IO::WRITABLE
		end
	else
		if wrapper.wait_any(timeout)
			return events
		end
	end
	
	return false
rescue TimeoutError
	return nil
ensure
	wrapper.reactor = nil
end

#kernel_sleep(duration) ⇒ Object


87
88
89
# File 'lib/async/scheduler.rb', line 87

def kernel_sleep(duration)
	self.block(nil, duration)
end

#process_wait(pid, flags) ⇒ Object

Wait for the specified process ID to exit.


81
82
83
84
85
# File 'lib/async/scheduler.rb', line 81

def process_wait(pid, flags)
	Thread.new do
		::Process::Status.wait(pid, flags)
	end.value
end

#set!Object


41
42
43
# File 'lib/async/scheduler.rb', line 41

def set!
	Fiber.set_scheduler(self)
end

#unblock(blocker, fiber) ⇒ Object


95
96
97
# File 'lib/async/scheduler.rb', line 95

def unblock(blocker, fiber)
	@reactor.unblock(blocker, fiber)
end