Class: Rake::Promise
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rake/promise.rb |
Overview
A Promise object represents a promise to do work (a chore) in the future. The promise is created with a block and a list of arguments for the block. Calling value will return the value of the promised chore.
Used by ThreadPool.
Constant Summary
-
NOT_SET =
# File 'lib/rake/promise.rb', line 12Object.new.freeze
Class Method Summary
-
.new(args, &block) ⇒ Promise
constructor
Create a promise to do the chore specified by the block.
Instance Attribute Summary
- #recorder rw
-
#complete? ⇒ Boolean
readonly
private
Are we done with the promise.
-
#error? ⇒ Boolean
readonly
private
Did the promise throw an error.
-
#result? ⇒ Boolean
readonly
private
Do we have a result for the promise.
Instance Method Summary
-
#value
Return the value of this promise.
-
#work
If no one else is working this promise, go ahead and do the chore.
-
#chore
private
Perform the chore promised.
-
#discard
private
free up these items for the GC.
-
#stat(*args)
private
Record execution statistics if there is a recorder.
Constructor Details
.new(args, &block) ⇒ Promise
Create a promise to do the chore specified by the block.
Instance Attribute Details
#complete? ⇒ Boolean
(readonly, private)
Are we done with the promise
#error? ⇒ Boolean
(readonly, private)
Did the promise throw an error
# File 'lib/rake/promise.rb', line 78
def error? !@error.equal?(NOT_SET) end
#recorder (rw)
[ GitHub ]# File 'lib/rake/promise.rb', line 14
attr_accessor :recorder
#result? ⇒ Boolean
(readonly, private)
Do we have a result for the promise
# File 'lib/rake/promise.rb', line 73
def result? !@result.equal?(NOT_SET) end
Instance Method Details
#chore (private)
Perform the chore promised
#discard (private)
free up these items for the GC
# File 'lib/rake/promise.rb', line 88
def discard @args = nil @block = nil end
#stat(*args) (private)
Record execution statistics if there is a recorder
# File 'lib/rake/promise.rb', line 94
def stat(*args) @recorder.call(*args) if @recorder end
#value
Return the value of this promise.
If the promised chore is not yet complete, then do the work synchronously. We will wait.
#work
If no one else is working this promise, go ahead and do the chore.