RejectedSoftware Forums

Sign up

Concurrent IO

Hi!

What is the "vibe.d way" to launch concurrent I/O ops and only resume the fiber when all of them complete?
Concretely, I have a bunch of independent DB queries that I would like to launch concurrently to reduce latency.

A quick search through examples and docs didn't give me any clues.

Re: Concurrent IO

On Sun, 31 Aug 2014 16:24:04 GMT, Màrcio Martins wrote:

Hi!

What is the "vibe.d way" to launch concurrent I/O ops and only resume the fiber when all of them complete?
Concretely, I have a bunch of independent DB queries that I would like to launch concurrently to reduce latency.

A quick search through examples and docs didn't give me any clues.

The generic way is to use one task per concurrent operation:

Task[] tasks;
tasks ~= runTask({ ... perform first query ... });
tasks ~= runTask({ ... perform second query ... });
tasks ~= runTask({ ... perform third query ... });
tasks ~= runTask({ ... perform fourth query ... });
foreach (t; tasks) t.join(); // wait for all tasks to finish

Some DBs also support request pipelining, which may be a good alternative in some situations, but this currently isn't supported by the MongoDB and Redis drivers.

Re: Concurrent IO

Great!

Thanks Sönke!