dtas.git  about / heads / tags
duct tape audio suite for *nix
blob 24d1ceed40e40bdf7a08f435ae61a056da7891b3 1026 bytes (raw)
$ git show v0.16.1:lib/dtas/writable_iter.rb	# shows this blob on the CLI

 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
 
# Copyright (C) 2013-2016 all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require_relative '../dtas'

# used to manage writable state for -player pipes
module DTAS::WritableIter # :nodoc:
  attr_accessor :on_writable
  # we may use the ready_write flag to avoid an extra IO.select
  attr_accessor :ready_write

  def writable_iter_init
    @mark_writable = proc { @ready_write = true }
    @on_writable = nil
    @ready_write = true
  end

  def ready_write_optimized?
    rv = @ready_write
    @ready_write = false
    rv
  end

  def wait_writable_prepare
    @ready_write = false
    @on_writable ||= @mark_writable
  end

  # this is used to exchange our own writable status for the readable
  # status of the DTAS::Buffer which triggered us.
  def writable_iter
    if owr = @on_writable
      @on_writable = nil
      @ready_write = true
      owr.call # this triggers readability watching of DTAS::Buffer
    end
    :ignore
  end
end

git clone git://80x24.org/dtas.git
git clone https://80x24.org/dtas.git