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.
Attributes 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(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
#catch, #finally, #progress, #ruby_catch, #value
Constructor Details
#initialize(thread, work) ⇒ Work
Returns a new instance of Work.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/libuv/work.rb', line 18 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(@reactor, @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.
8 9 10 |
# File 'lib/libuv/work.rb', line 8 def error @error end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
9 10 11 |
# File 'lib/libuv/work.rb', line 9 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.
39 40 41 42 43 44 |
# File 'lib/libuv/work.rb', line 39 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.
49 50 51 |
# File 'lib/libuv/work.rb', line 49 def completed? return @complete end |