libdtasks 0.0.5

A minimal tasking D library


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

pipeline status

libdtasks

About

Minimal tasking library written in the D programming language. This library was heavily influenced by Sean Parent's concurrency talks, as well as Chrome's task runners.

It currently supports a SingleThreadTaskRunner that is capable of either running tasks on the current thread, or spawning a single new thread on which it will run any posted tasks asynchronously.

It also supports a ThreadPoolTaskRunner that spwans as many threads as the number of CPUs the runtime machine has, and posted tasks will run asynchronously on any of those threads with any arbitrary sequence and order.

Examples

Here's an example of using two task runners, one that is running on the current thread, and one that spawns a single new thread. This example uses postTaskAndReplyWithResult to run a task that returns a result and invoke a reply that accepts that result as an argument. The two tasks are run of two different threads.

int number;
// |runner2| spawns a single new thread.
SingleThreadTaskRunner runner2 = new SingleThreadTaskRunner(
    SingleThreadTaskRunner.Type.kNewThread, null /* no initial task to run */);
// |runner1| runs on the current thread.
new SingleThreadTaskRunner(SingleThreadTaskRunner.Type.kCurrentThread, {
  AbstractTaskRunner runner1 =
      TaskSystem.get().getCurrentThreadTaskRunner();

  // The result type is an `int`.
  runner2.postTaskAndReplyWithResult!int(
      {
        // Task to be run on runner2 on thread2.
        import std.math : sqrt;
        return cast(int) sqrt(400.0f);
      },
      (int result) {
        // Reply to be run on runner1 on thread1.
        assert(result == 20);
        number = result;

        // Shutdown both runners.
        runner2.shutdown();
        runner1.shutdown();
      });
});

assert(number == 20);

See unittests for more examples.

License

MIT

Authors:
  • Ahmed Fakhry
Dependencies:
none
Versions:
0.0.5 2018-Jun-16
0.0.4 2018-Jun-16
0.0.3 2017-Dec-23
0.0.2 2017-Dec-15
0.0.1 2017-Dec-12
Show all 6 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 25 downloads total

Score:
0.0
Short URL:
libdtasks.dub.pm