Futures and Promises - Read-only Views

Read-only Views

In some programming languages such as Oz, E, and AmbientTalk, it is possible to obtain a read-only view of a future, which allows reading its value when resolved, but does not permit resolving it:

  • In Oz, the !! operator is used to obtain a read-only view.
  • In E and AmbientTalk, a future is represented by a pair of values called a promise/resolver pair. The promise represents the read-only view, and the resolver is needed in order to set the future's value.
  • In C++11 a std::future provides a read-only view. The value is set directly by using a std::promise, or set to the result of a function call using std::packaged_task or std::async.
  • In the Dojo Toolkit's Deferred API as of version 1.5, a consumer-only promise object represents a read-only view.
  • In Alice ML, futures only provide a read-only view, whereas a promise contains both a future and the ability to resolve the future
  • In .NET 4.0 System.Threading.Tasks.Task represents a read-only view. Resolving the value can be done through System.Threading.Tasks.TaskCompletionSource.

Support for read-only views is consistent with the Principle of Least Authority, since it enables the ability to set the value to be restricted to subjects that need to set it. In a system that also supports pipelining, the sender of an asynchronous message (with result) receives the read-only promise for the result, and the target of the message receives the resolver.

Read more about this topic:  Futures And Promises

Famous quotes containing the word views:

    It is even more grim and wild than you had anticipated, a damp and intricate wilderness, in the spring everywhere wet and miry. The aspect of the country, indeed, is universally stern and savage, excepting the distant views of the forest from hills, and the lake prospects, which are mild and civilizing in a degree.
    Henry David Thoreau (1817–1862)