Skip to content
Snippets Groups Projects
Commit d03657e6 authored by cleemy desu wayo's avatarcleemy desu wayo
Browse files

Fix bug: fix weird way to manipulate Thread

parent 818e5ce1
Branches main
No related tags found
No related merge requests found
#!/usr/bin/env ruby
#
# ==========================================================================
# Outvoke -- version 0.0.99.20240925.1
# Outvoke -- version 0.0.99.20240928
#
# written by cleemy desu wayo / Licensed under CC0 1.0
#
......@@ -23,7 +23,7 @@ class Outvoke
@version = Struct.new(:branch, :body).new(
'0.1',
'0.0.99.20240925.1'
'0.0.99.20240928'
)
@sources = Hash.new
......@@ -410,23 +410,35 @@ class OutvokeDataSourceStdin < OutvokeDataSource
@thread_stdin = Thread.new do
Thread.stop
loop do
tmp = @stdin.next
Thread.stop unless @is_enabled
Thread.current["tmp"] = @stdin.next
Thread.stop unless @is_enabled
@mutex_stdin.synchronize do
@stdin_new_lines << tmp.chomp
@stdin_new_lines << Thread.current["tmp"].chomp
end
end
end
end
def enabled=(x)
@is_enabled = x
@is_enabled = !!x
if @is_enabled
sleep 0.05 # TODO
@thread_stdin.run
else
@thread_stdin.stop
return false unless @is_enabled
sleep 0.05 # TODO
tmp_status = @thread_stdin.status
if tmp_status == "run" || tmp_status == "sleep"
begin
@thread_stdin.run
rescue ThreadError
return false
end
end
true
end
def each_event
......
# for Outvoke 0.1
# written by cleemy desu wayo / Licensed under CC0 1.0
# initial release of this sample: 2024-09-28
# --------
#
# this is a sample code to check for the presence of a bug that is fixed in
# Outvoke version 0.0.99.20240928.
#
# usage:
#
# $ seq 1 3 | ./outvoke.rb samples/2024/fixbug_20240928_stdin_001.rb
#
using OutvokeDSL
hook "stdin"
sleep 1
hook "stdin"
# for Outvoke 0.1
# written by cleemy desu wayo / Licensed under CC0 1.0
# initial release of this sample: 2024-09-28
# --------
#
# this is a sample code to check for the presence of a bug that is fixed in
# Outvoke version 0.0.99.20240928.
#
# usage:
#
# $ { i=0 ; while true ; do echo "$i" ; sleep 1 ; i=$(expr "$i" + 1) ; done ; } | ./outvoke.rb samples/2024/fixbug_20240928_stdin_002.rb
#
using OutvokeDSL
hook "every-sec", / ..:..:.[0]/ do |e|
$outvoke.sources["stdin"].enabled = false
"set false ---- #{e.body}"
end
hook "every-sec", / ..:..:.[3]/ do |e|
$outvoke.sources["stdin"].enabled = true
"set true ---- #{e.body}"
end
hook "stdin"
$outvoke.sources["stdin"].enabled = false
    0% or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment