ae.utils.promise.concurrency

Promise concurrency tools.

Members

Classes

AsyncQueue
class AsyncQueue(T, E = Exception)

Runs tasks asynchronously in an ordered manner. For each put call, return a Promise which resolves to the given delegate's return value. The taskFun is evaluated in a separate thread. Unlike threadAsync, at most one task will execute at any given time (per AsyncQueue instance), they will be executed in the order of the put calls, and the promises will be resolved in the main thread in the same order.

Functions

threadAsync
Promise!(T, E) threadAsync(T value)
Promise!(T, E) threadAsync(T function() value)
Promise!(T, E) threadAsync(T delegate() value)

Evaluate value in a new thread. The promise is resolved in the current (calling) thread.

Templates

globallyMemoized
template globallyMemoized(alias fun)

Given a function fun which returns a promise, globally memoize it (across all threads), so that at most one invocation of fun with the given parameters is invoked during the program's lifetime. If a fun promise is in progress (incl. if started by another thread), wait for it to finish first.

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>