libfuture 1.0.0

This is an implementation of the await concept.


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:

This is an implementation of the await concept.

It provides a mechanism to treat each nested fiber as a single fiber.

  • Post-await syntax by using UFCS
  • JS's Promise-like Future!T construction (by resolve and reject)
  • C#-like FutureFactory
auto t = new Future!int(resolve => {
        import core.thread : Thread;
        new Thread({
            Thread.sleep(1.seconds);
            resolve(100);
        }).start();
    });

auto n = t.await;
assert(n == 100);
Future!string getHtmlAsync(string url) {
    return FutureFactory.startNew!string({
        import std.net.curl : get;
        return get(url);
    });
}

Future!size_t sumLength(string[] urls) {
    return new Future!size_t({
        size_t length = 0;
        foreach (url; urls) {
            const html = getHtmlAsync(url).await;
            length += html.length;
        }
        return length;
    });
}

Future!size_t sumLength2(string[] urls) {
    return new Future!size_t({
        import std.algorithm : map, sum;
        return urls.map!(a => getHtmlAsync(a).await.length).sum();
    });
}
Authors:
  • lempiji
Dependencies:
none
Versions:
1.0.0 2020-Oct-14
~master 2020-Oct-14
Show all 2 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 666 downloads total

Score:
0.4
Short URL:
libfuture.dub.pm