www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Async await problem solved

reply aberba <karabutaworld gmail.com> writes:
It's been there for a while.

 This library provides a very easy-to-use async/await library 
 for D. It consists of only three functions: async, await, and 
 startScheduler. The library is build on top of D's fibers and 
 allows for easier cooperative multitasking.
import std.stdio; int calculateTheAnswer() { import core.thread : Thread; Thread.sleep(5.seconds); return 42; } void doTask() { writeln("Calculating the answer to life, the universe, and everything..."); int answer = await(calculateTheAnswer()); writeln("The answer is: ", answer); } void main() { startScheduler({ doTask(); }); } https://code.dlang.org/packages/dawait
Dec 09 2020
next sibling parent RSY <rsy_881 gmail.com> writes:
On Wednesday, 9 December 2020 at 09:16:31 UTC, aberba wrote:
 It's been there for a while.

 This library provides a very easy-to-use async/await library 
 for D. It consists of only three functions: async, await, and 
 startScheduler. The library is build on top of D's fibers and 
 allows for easier cooperative multitasking.
import std.stdio; int calculateTheAnswer() { import core.thread : Thread; Thread.sleep(5.seconds); return 42; } void doTask() { writeln("Calculating the answer to life, the universe, and everything..."); int answer = await(calculateTheAnswer()); writeln("The answer is: ", answer); } void main() { startScheduler({ doTask(); }); } https://code.dlang.org/packages/dawait
nice library! thanks for sharing!
Dec 11 2020
prev sibling next sibling parent Dukc <ajieskola gmail.com> writes:
On Wednesday, 9 December 2020 at 09:16:31 UTC, aberba wrote:
 This library provides a very easy-to-use async/await library 
 for D. It consists of only three functions: async, await, and 
 startScheduler. The library is build on top of D's fibers and 
 allows for easier cooperative multitasking.
How does this differ from std.concurrency.Generator?
Dec 11 2020
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2020-12-09 10:16, aberba wrote:
 It's been there for a while.
 
 This library provides a very easy-to-use async/await library for D. It 
 consists of only three functions: async, await, and startScheduler. 
 The library is build on top of D's fibers and allows for easier 
 cooperative multitasking.
import std.stdio; int calculateTheAnswer() {     import core.thread : Thread;     Thread.sleep(5.seconds);     return 42; } void doTask() {     writeln("Calculating the answer to life, the universe, and everything...");     int answer = await(calculateTheAnswer());     writeln("The answer is: ", answer); } void main() {     startScheduler({         doTask();     }); } https://code.dlang.org/packages/dawait
I don't think it's that simple. To be efficient you need to use no-blocking IO and have an event loop as well. -- /Jacob Carlborg
Dec 11 2020