Sha256: 8a7bfff4a2316597b09702a531f40f74c1f52a1f8fd91ef186064fbb7dd37a3d
Contents?: true
Size: 813 Bytes
Versions: 5
Compression:
Stored size: 813 Bytes
Contents
module UV class Work include Resource, Listener def initialize(loop, work, callback = nil) @loop, @work, @callback = loop, work, callback @complete = false @pointer = UV.create_request(:uv_work) begin check_result! UV.queue_work(@loop, @pointer, callback(:on_work), callback(:on_complete)) rescue StandardError => e UV.free(@pointer) @complete = true raise e end end def cancel if not @complete check_result! UV.cancel(@pointer) @complete = true end end def completed? return @complete end private def on_complete(req) @complete = true UV.free(req) @callback.call unless @callback.nil? end def on_work(req) @work.call end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
uvrb-0.2.0 | lib/uv/work.rb |
uvrb-0.1.4 | lib/uv/work.rb |
uvrb-0.1.3 | lib/uv/work.rb |
uvrb-0.1.2 | lib/uv/work.rb |
uvrb-0.1.1 | lib/uv/work.rb |