Created
June 12, 2014 04:39
-
-
Save taichi/f7bdf9713017892797b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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