Skip to content

Instantly share code, notes, and snippets.

@jpcamara
Last active December 24, 2023 11:46

Revisions

  1. jpcamara revised this gist Dec 24, 2023. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions fifo_async.rb
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@ def mkcdtmpdir
    w.write "foo"
    }
    }
    # Hangs indefinitely
    puts t1.wait
    end
    }
  2. jpcamara revised this gist Dec 24, 2023. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions fifo_async.rb
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,11 @@
    require "async"

    def mkcdtmpdir
    Dir.mktmpdir {|d|
    Dir.chdir(d) {
    yield
    }
    }
    Dir.mktmpdir {|d|
    Dir.chdir(d) {
    yield
    }
    }
    end

    mkcdtmpdir {
  3. jpcamara created this gist Dec 24, 2023.
    31 changes: 31 additions & 0 deletions fifo_async.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # hangs, same as MN threads
    # RUBY_MN_THREADS=1 make test-all TESTS="--name=TestIO#test_open_fifo_does_not_block_other_threads"

    require "tempfile"
    require "async"

    def mkcdtmpdir
    Dir.mktmpdir {|d|
    Dir.chdir(d) {
    yield
    }
    }
    end

    mkcdtmpdir {
    File.mkfifo("fifo")

    Async do |task|
    t1 = task.async {
    open("fifo", "r") {|r|
    r.read
    }
    }
    t2 = task.async {
    open("fifo", "w") {|w|
    w.write "foo"
    }
    }
    puts t1.wait
    end
    }