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



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

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



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

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