Sha256: 00c7d50a7f5d3cfadbb3a6ca425bfb8e332b06717cf1c73191334ddc7bf2a715
Contents?: true
Size: 999 Bytes
Versions: 3
Compression:
Stored size: 999 Bytes
Contents
# frozen_string_literal: true module Aw # The Fork class. class Fork # Initialize the class. # # @param read [IO] The read endpoint. # @param write [IO] The write endpoint. def initialize(read, write) @read = read @write = write end # @!attribute [r] read # # @return [IO] The read endpoint. attr_reader :read # @!attribute [r] write # # @return [IO] The write endpoint. attr_reader :write # Run the block inside a subprocess, and return the value. # # @return [#object_id] The result. def call(*, **, &block) pid = fork_and_return_pid(&block) write.close result = read.read Process.wait(pid) # rubocop:disable MarshalLoad Marshal.load(result) # rubocop:enable MarshalLoad end private def fork_and_return_pid fork do read.close result = yield Marshal.dump(result, write) exit!(0) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aw-0.1.5 | lib/aw/fork.rb |
aw-0.1.4 | lib/aw/fork.rb |
aw-0.1.3 | lib/aw/fork.rb |