/usr/lib/ruby/vendor_ruby/em/spawnable.rb is in ruby-eventmachine 1.0.3-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #--
#
# Author:: Francis Cianfrocca (gmail: blackhedd)
# Homepage:: http://rubyeventmachine.com
# Date:: 25 Aug 2007
#
# See EventMachine and EventMachine::Connection for documentation and
# usage examples.
#
#----------------------------------------------------------------------------
#
# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
# Gmail: blackhedd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of either: 1) the GNU General Public License
# as published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version; or 2) Ruby's License.
#
# See the file COPYING for complete licensing information.
#
#---------------------------------------------------------------------------
#
#
module EventMachine
# Support for Erlang-style processes.
#
class SpawnedProcess
# Send a message to the spawned process
def notify *x
me = self
EM.next_tick {
# A notification executes in the context of this
# SpawnedProcess object. That makes self and notify
# work as one would expect.
#
y = me.call(*x)
if y and y.respond_to?(:pull_out_yield_block)
a,b = y.pull_out_yield_block
set_receiver a
self.notify if b
end
}
end
alias_method :resume, :notify
alias_method :run, :notify # for formulations like (EM.spawn {xxx}).run
def set_receiver blk
(class << self ; self ; end).class_eval do
remove_method :call if method_defined? :call
define_method :call, blk
end
end
end
# @private
class YieldBlockFromSpawnedProcess
def initialize block, notify
@block = [block,notify]
end
def pull_out_yield_block
@block
end
end
# Spawn an erlang-style process
def self.spawn &block
s = SpawnedProcess.new
s.set_receiver block
s
end
# @private
def self.yield &block
return YieldBlockFromSpawnedProcess.new( block, false )
end
# @private
def self.yield_and_notify &block
return YieldBlockFromSpawnedProcess.new( block, true )
end
end
|