Skip to content

Instantly share code, notes, and snippets.

@taichi
Created June 12, 2014 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taichi/f7bdf9713017892797b8 to your computer and use it in GitHub Desktop.
Save taichi/f7bdf9713017892797b8 to your computer and use it in GitHub Desktop.
require 'gson'
module Yajl
class Parser
attr_accessor :on_parse_complete
def initialize
@delegate = Gson::Decoder.new
@reader, @writer = IO.pipe
end
def start
Thread.new do
begin
puts "wwwwwwwwwwwwww"
json = @delegate.decode(@reader)
#json = @delegate.decode("{aaa:111111}")
puts "***************** " + json.to_s
#on_parse_complete.call json
puts "zzzzzzzzzzzzzzzzzzzzzzzzzz"
rescue => e
puts e
end
end
end
def << (data)
@writer.puts data
@writer.fsync
end
end
end
puts Gson::Decoder.new.decode("{hoge:11}")
10.times do
y = Yajl::Parser.new
y.on_parse_complete = lambda { |obj|
puts obj
}
y.start
y << "{aaa:1,bbb:2}"
y << "\n"
#y << "{aaa:1,bbb:2}]"
#y << "\n"
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment