Class: Concurrent::Promises::ResolvableFuture
- Inherits:
-
Future
- Object
- Synchronization::AbstractObject
- Synchronization::Object
- AbstractEventFuture
- Future
- Concurrent::Promises::ResolvableFuture
- Includes:
- Resolvable
- Defined in:
- lib/concurrent-ruby/concurrent/promises.rb
Overview
A Future which can be resolved by user.
Instance Method Summary collapse
-
#evaluate_to(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future's value fulfilling, if the block raises an exception the future rejects with it.
-
#evaluate_to!(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future's value fulfilling, if the block raises an exception the future rejects with it.
-
#fulfill(value, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future fulfilled with
value
, which triggers all dependent futures. -
#reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Exception, timeout_value, nil
Behaves as Future#reason but has one additional optional argument resolve_on_timeout.
-
#reject(reason, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future rejected with
reason
, which triggers all dependent futures. -
#resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future resolved with result of triplet
fulfilled?
,value
,reason
, which triggers all dependent futures. -
#result(timeout = nil, resolve_on_timeout = nil) ⇒ ::Array(Boolean, Object, Exception), nil
Behaves as Future#result but has one additional optional argument resolve_on_timeout.
-
#value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, timeout_value, nil
Behaves as Future#value but has one additional optional argument resolve_on_timeout.
-
#value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, timeout_value, nil
Behaves as Future#value! but has one additional optional argument resolve_on_timeout.
-
#wait(timeout = nil, resolve_on_timeout = nil) ⇒ self, true, false
Behaves as AbstractEventFuture#wait but has one additional optional argument resolve_on_timeout.
-
#wait!(timeout = nil, resolve_on_timeout = nil) ⇒ self, true, false
Behaves as Future#wait! but has one additional optional argument resolve_on_timeout.
-
#with_hidden_resolvable ⇒ Future
Creates new future wrapping receiver, effectively hiding the resolve method and similar.
-
#release ⇒ true, false
included
from Resolvable
On successful release of the reservation.
-
#reserve ⇒ true, false
included
from Resolvable
Reserves the event or future, if reserved others are prevented from resolving it.
Instance Method Details
#evaluate_to(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future's value fulfilling, if the block raises an exception the future rejects with it.
1395 1396 1397 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1395 def evaluate_to(*args, &block) promise.evaluate_to(*args, block) end |
#evaluate_to!(*args) {|*args| ... } ⇒ self
Evaluates the block and sets its result as future's value fulfilling, if the block raises an exception the future rejects with it.
1406 1407 1408 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1406 def evaluate_to!(*args, &block) promise.evaluate_to(*args, block).wait! end |
#fulfill(value, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future fulfilled with value
,
which triggers all dependent futures.
1375 1376 1377 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1375 def fulfill(value, raise_on_reassign = true, reserved = false) resolve_with Fulfilled.new(value), raise_on_reassign, reserved end |
#reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Exception, timeout_value, nil
Behaves as Future#reason but has one additional optional argument resolve_on_timeout.
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1503 def reason(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.reason else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout return internal_state.reason end end timeout_value end end |
#reject(reason, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future rejected with reason
,
which triggers all dependent futures.
1385 1386 1387 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1385 def reject(reason, raise_on_reassign = true, reserved = false) resolve_with Rejected.new(reason), raise_on_reassign, reserved end |
#resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) ⇒ self, false
Makes the future resolved with result of triplet fulfilled?
, value
, reason
,
which triggers all dependent futures.
1365 1366 1367 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1365 def resolve(fulfilled = true, value = nil, reason = nil, raise_on_reassign = true, reserved = false) resolve_with(fulfilled ? Fulfilled.new(value) : Rejected.new(reason), raise_on_reassign, reserved) end |
#result(timeout = nil, resolve_on_timeout = nil) ⇒ ::Array(Boolean, Object, Exception), nil
Behaves as Future#result but has one additional optional argument resolve_on_timeout.
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1524 def result(timeout = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.result else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout internal_state.result end end # otherwise returns nil end end |
#value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, timeout_value, nil
Behaves as Future#value but has one additional optional argument resolve_on_timeout.
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1459 def value(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved timeout internal_state.value else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout return internal_state.value end end timeout_value end end |
#value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) ⇒ Object, timeout_value, nil
Behaves as Future#value! but has one additional optional argument resolve_on_timeout.
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1481 def value!(timeout = nil, timeout_value = nil, resolve_on_timeout = nil) if wait_until_resolved! timeout internal_state.value else if resolve_on_timeout unless resolve(*resolve_on_timeout, false) # if it fails to resolve it was resolved in the meantime # so return value as if there was no timeout raise self if rejected? return internal_state.value end end timeout_value end end |
#wait(timeout = nil, resolve_on_timeout = nil) ⇒ self, true, false
Behaves as AbstractEventFuture#wait but has one additional optional argument resolve_on_timeout.
1421 1422 1423 1424 1425 1426 1427 1428 1429 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1421 def wait(timeout = nil, resolve_on_timeout = nil) super(timeout) or if resolve_on_timeout # if it fails to resolve it was resolved in the meantime # so return true as if there was no timeout !resolve(*resolve_on_timeout, false) else false end end |
#wait!(timeout = nil, resolve_on_timeout = nil) ⇒ self, true, false
Behaves as Future#wait! but has one additional optional argument resolve_on_timeout.
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1438 def wait!(timeout = nil, resolve_on_timeout = nil) super(timeout) or if resolve_on_timeout if resolve(*resolve_on_timeout, false) false else # if it fails to resolve it was resolved in the meantime # so return true as if there was no timeout raise self if rejected? true end else false end end |
#with_hidden_resolvable ⇒ Future
Creates new future wrapping receiver, effectively hiding the resolve method and similar.
1542 1543 1544 |
# File 'lib/concurrent-ruby/concurrent/promises.rb', line 1542 def with_hidden_resolvable @with_hidden_resolvable ||= FutureWrapperPromise.new_blocked_by1(self, @DefaultExecutor).future end |
#release ⇒ true, false Originally defined in module Resolvable
Returns on successful release of the reservation.
#reserve ⇒ true, false Originally defined in module Resolvable
Reserves the event or future, if reserved others are prevented from resolving it. Advanced feature. Be careful about the order of reservation to avoid deadlocks, the method blocks if the future or event is already reserved until it is released or resolved.