Module: Chan

Defined in:
lib/xchan.rb,
lib/xchan/version.rb,
lib/xchan/tempfile.rb

Defined Under Namespace

Classes: Bytes, Counter, UNIXSocket

Constant Summary collapse

WaitReadable =
Class.new(IO::EAGAINWaitReadable)
WaitWritable =
Class.new(IO::EAGAINWaitWritable)
WaitLockable =
Class.new(Errno::EWOULDBLOCK)
Pure =

Coerces an object to a string for a channel communicating in raw strings (in other words: without serialization)

Examples:

ch = xchan(:pure)
fork { ch.send "Hello world" }
Process.wait
puts ch.recv
Class.new do
  def self.dump(str) = str.to_s
  def self.load(str) = str.to_s
end
VERSION =
"0.18.0"

Class Method Summary collapse

Class Method Details

.temporary_file(basename, tmpdir: Dir.tmpdir) ⇒ Chan::Tempfile

Returns an unlinked Chan::Tempfile object that can be read from, and written to by the process that created it, inclusive of its child processes, but not of processes other than that.

Parameters:

  • basename (String)

    Basename of the temporary file

  • tmpdir (String) (defaults to: Dir.tmpdir)

    Parent directory of the temporary file

Returns:

  • (Chan::Tempfile)

    Returns an instance of Chan::Tempfile



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

def self.temporary_file(basename, tmpdir: Dir.tmpdir)
  Chan::Tempfile.new(basename, tmpdir, perm: 0).tap(&:unlink)
end

.serializersHash<Symbol, Proc>

Returns the default serializers

Returns:

  • (Hash<Symbol, Proc>)

    Returns the default serializers



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xchan.rb', line 48

def self.serializers
  {
    pure: lambda { Pure },
    marshal: lambda { Marshal },
    json: lambda {
      require "json" unless defined?(JSON)
      JSON
    },
    yaml: lambda {
      require "yaml" unless defined?(YAML)
      YAML
    }
  }
end