Class: Libuv::Work
- Inherits:
-
Q::DeferredPromise
- Object
- Q::Promise
- Q::DeferredPromise
- Libuv::Work
- Defined in:
- lib/libuv/work.rb
Constant Summary
Constants inherited from Q::Promise
Instance Method Summary collapse
-
#cancel ⇒ true, false
Attempt to cancel the pending work.
-
#completed? ⇒ true, false
Indicates is the work has completed yet or not.
-
#initialize(loop, work) ⇒ Work
constructor
A new instance of Work.
Methods included from Resource
#check_result, #check_result!, #resolve, #to_ptr
Methods inherited from Q::DeferredPromise
Methods inherited from Q::Promise
Constructor Details
#initialize(loop, work) ⇒ Work
Returns a new instance of Work.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/libuv/work.rb', line 8 def initialize(loop, work) super(loop, loop.defer) @work = work @complete = false @pointer = ::Libuv::Ext.create_request(:uv_work) @error = nil # error in callback error = check_result ::Libuv::Ext.queue_work(@loop, @pointer, callback(:on_work), callback(:on_complete)) if error ::Libuv::Ext.free(@pointer) @complete = true @defer.reject(error) end end |
Instance Method Details
#cancel ⇒ true, false
Attempt to cancel the pending work. Returns true if the work has completed or was canceled.
27 28 29 30 31 32 |
# File 'lib/libuv/work.rb', line 27 def cancel if not @complete @complete = ::Libuv::Ext.cancel(@pointer) >= 0 end @complete end |
#completed? ⇒ true, false
Indicates is the work has completed yet or not.
37 38 39 |
# File 'lib/libuv/work.rb', line 37 def completed? return @complete end |