Promise[A: Any #share]

[Source]

A promise to eventually produce a result of type A. This promise can either be fulfilled or rejected.

Any number of promises can be chained after this one.

actor tag Promise[A: Any #share]

Constructors

create

[Source]

new tag create()
: Promise[A] tag^

Returns

Public Behaviours

apply

[Source]

Fulfill the promise.

be apply(
  value: A)

Parameters

  • value: A

reject

[Source]

Reject the promise.

be reject()

Public Functions

next[B: Any #share]

[Source]

Chain a promise after this one.

When this promise is fulfilled, the result of type A is passed to the fulfill function, generating in an intermediate result of type B. This is then used to fulfill the next promise in the chain.

If there is no fulfill function, or if the fulfill function raises an error, then the next promise in the chain will be rejected.

If this promise is rejected, this step's reject function is called with no input, generating an intermediate result of type B which is used to fulfill the next promise in the chain.

If there is no reject function, of if the reject function raises an error, then the next promise in the chain will be rejected.

fun tag next[B: Any #share](
  fulfill: Fulfill[A, B] iso,
  rejected: Reject[B] iso = qualify)
: Promise[B] tag

Parameters

Returns

add[optional B: Any #share]

[Source]

Add two promises into one promise that returns the result of both when they are fulfilled. If either of the promises is rejected then the new promise is also rejected.

fun tag add[optional B: Any #share](
  p: Promise[B] tag)
: Promise[(A , B)] tag

Parameters

Returns

join

[Source]

Create a promise that is fulfilled when the receiver and all promises in the given iterator are fulfilled. If the receiver or any promise in the sequence is rejected then the new promise is also rejected.

Join p1 and p2 with an existing promise, p3.

use "promises"

actor Main
  new create(env: Env) =>

    let p1 = Promise[String val]
    let p2 = Promise[String val]
    let p3 = Promise[String val]

    p3.join([p1; p2].values())
      .next[None]({(a: Array[String val] val) =>
        for s in a.values() do
          env.out.print(s)
        end
      })

    p2("second")
    p3("third")
    p1("first")
fun tag join(
  ps: Iterator[Promise[A] tag] ref)
: Promise[Array[A] val] tag

Parameters

Returns

select

[Source]

Return a promise that is fulfilled when either promise is fulfilled, resulting in a tuple of its value and the other promise.

fun tag select(
  p: Promise[A] tag)
: Promise[(A , Promise[A] tag)] tag

Parameters

Returns

timeout

[Source]

Reject the promise after the given expiration in nanoseconds.

fun tag timeout(
  expiration: U64 val)
: None val

Parameters

  • expiration: U64 val

Returns

© 2016-2020, The Pony Developers
© 2014-2015, Causality Ltd.
Licensed under the BSD 2-Clause License.
https://stdlib.ponylang.io/promises-Promise