diff --git a/lib/modules/Concurrent.pmod b/lib/modules/Concurrent.pmod index a78730beb99a648c3dd089503fdb2dfff9aefc30..1a4b65a7ea62bb7aed8447965f63a1086e8e82d6 100644 --- a/lib/modules/Concurrent.pmod +++ b/lib/modules/Concurrent.pmod @@ -163,7 +163,7 @@ class Future //! Wait for fulfillment. //! //! @seealso - //! @[get()] + //! @[get()], @[try_get()] this_program wait() { if (state <= STATE_PENDING) { @@ -182,7 +182,7 @@ class Future //! Throws on rejection. //! //! @seealso - //! @[wait()] + //! @[wait()], @[try_get()] mixed get() { wait(); @@ -193,6 +193,28 @@ class Future return result; } + //! Return the value if available. + //! + //! @returns + //! Returns @[UNDEFINED] if the @[Future] is not yet fulfilled. + //! + //! @throws + //! Throws on rejection. + //! + //! @seealso + //! @[wait()] + mixed try_get() + { + switch(state) { + case ..STATE_PENDING: + return UNDEFINED; + case STATE_REJECTED..: + throw(result); + default: + return result; + } + } + //! Register a callback that is to be called on fulfillment. //! //! @param cb