Shorthand for the client type this instance operates on.
Whether to open the underlying transports of a client before trying to execute a method if they are not open. This is usually desirable because it allows e.g. to automatically reconnect to a remote server if the network connection is dropped.
// Some Thrift service. interface Foo { int foo(string name); byte[] bar(); } // Create the aggregator pool – client0, client1, client2 are some // TAsyncClient!Foo instances, but in theory could also be other // TFutureInterface!Foo implementations (e.g. some async client pool). auto pool = new TAsyncAggregator!Foo([client0, client1, client2]); foreach (val; pool.foo("baz").range(dur!"seconds"(1))) { // Process all the results that are available before a second has passed, // in the order they arrive. writeln(val); } auto sumRoots = pool.foo("baz").accumulate!((int[] vals, Exceptions[] exs){ if (vals.empty) { throw new TCompoundOperationException("All clients failed", exs); } // Just to illustrate that the type of the values can change, convert the // numbers to double and sum up their roots. double result = 0; foreach (v; vals) result += sqrt(cast(double)v); return result; })(); // Wait up to three seconds for the result, and then accumulate what has // arrived so far. sumRoots.completion.wait(dur!"seconds"(3)); writeln(sumRoots.finishGet()); // For scalars, the default accumulator returns an array of the values. pragma(msg, typeof(pool.foo("").accumulate().get()); // int[]. // For lists, etc., it concatenates the results together. pragma(msg, typeof(pool.bar().accumulate().get())); // byte[].
Note: For the accumulate!() interface, you might currently hit a »cannot use local '…' as parameter to non-global template accumulate«-error, see $(DMDBUG 5710, DMD issue 5710). If your accumulator function does not need to access the surrounding scope, you might want to use a function literal instead of a delegate to avoid the issue.
Allows easily aggregating results from a number of TAsyncClients.
Contrary to TAsync{Fallback, Fastest}ClientPool, this class does not simply implement TFutureInterface!Interface. It manages a pool of clients, but allows the user to specify a custom accumulator function to use or to iterate over the results using a TFutureAggregatorRange.
For each service method, TAsyncAggregator offers a method accepting the same arguments, and an optional TCancellation instance, just like with TFutureInterface. The return type, however, is a proxy object that offers the following methods: