Class: Async::Container::Thread::Instance

Inherits:
Notify::Pipe show all
Defined in:
lib/async/container/thread.rb

Constant Summary

Constants inherited from Notify::Pipe

Notify::Pipe::NOTIFY_PIPE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Notify::Pipe

#before_spawn, open!, #ready!, #reloading!, #send

Methods inherited from Notify::Client

#error!, #ready!, #reloading!, #restarting!, #status!, #stopping!

Constructor Details

#initialize(io) ⇒ Instance

Returns a new instance of Instance.



50
51
52
53
54
55
# File 'lib/async/container/thread.rb', line 50

def initialize(io)
	@name = nil
	@thread = ::Thread.current
	
	super
end

Class Method Details

.for(thread) ⇒ Object



44
45
46
47
48
# File 'lib/async/container/thread.rb', line 44

def self.for(thread)
	instance = self.new(thread.out)
	
	return instance
end

Instance Method Details

#exec(*arguments, ready: true, **options) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/async/container/thread.rb', line 65

def exec(*arguments, ready: true, **options)
	if ready
		self.ready!(status: "(spawn)") if ready
	else
		self.before_spawn(arguments, options)
	end
	
	begin
		# TODO prefer **options... but it doesn't support redirections on < 2.7
		pid = ::Process.spawn(*arguments, options)
	ensure
		_, status = ::Process.wait2(pid)
		
		raise Exit, status
	end
end

#nameObject



61
62
63
# File 'lib/async/container/thread.rb', line 61

def name
	@thread.name
end

#name=(value) ⇒ Object



57
58
59
# File 'lib/async/container/thread.rb', line 57

def name= value
	@thread.name = value
end