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 Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
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(thread, 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(thread, work) ⇒ Work
Returns a new instance of Work.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/libuv/work.rb', line 16 def initialize(thread, work) super(thread, thread.defer) @work = work @complete = false @pointer = ::Libuv::Ext.allocate_request_work @error = nil # error in callback @instance_id = @pointer.address 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 Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/libuv/work.rb', line 6 def error @error end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/libuv/work.rb', line 7 def result @result end |
Instance Method Details
#cancel ⇒ true, false
Attempt to cancel the pending work. Returns true if the work has completed or was canceled.
37 38 39 40 41 42 |
# File 'lib/libuv/work.rb', line 37 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.
47 48 49 |
# File 'lib/libuv/work.rb', line 47 def completed? return @complete end |