Re: Implement async/await using Fiber

2016-05-20 Thread Ali Çehreli via Digitalmars-d-learn
On 05/20/2016 12:56 PM, Yuxuan Shui wrote: > On Friday, 20 May 2016 at 06:40:42 UTC, Jacob Carlborg wrote: >> On 2016-05-20 04:14, Yuxuan Shui wrote: >> >>> Hmm... This could work. But I'm not satisfied with this solution. What >>> if I have multiple yield sites in the fiber, and each have differe

Re: Implement async/await using Fiber

2016-05-20 Thread Yuxuan Shui via Digitalmars-d-learn
On Friday, 20 May 2016 at 06:40:42 UTC, Jacob Carlborg wrote: On 2016-05-20 04:14, Yuxuan Shui wrote: Hmm... This could work. But I'm not satisfied with this solution. What if I have multiple yield sites in the fiber, and each have different return types? Maybe I should use a Variant? I th

Re: Implement async/await using Fiber

2016-05-19 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-05-20 04:14, Yuxuan Shui wrote: Hmm... This could work. But I'm not satisfied with this solution. What if I have multiple yield sites in the fiber, and each have different return types? Maybe I should use a Variant? I think you can view "yield" as a form of "return". If you cannot ret

Re: Implement async/await using Fiber

2016-05-19 Thread Yuxuan Shui via Digitalmars-d-learn
On Thursday, 19 May 2016 at 23:42:03 UTC, Ali Çehreli wrote: On 05/19/2016 12:57 PM, Yuxuan Shui wrote: [...] You can use a delegate that takes a ref parameter: import std.stdio; import core.thread; void fiberFunc(ref string y) { y = "produced_by_fiberFunc"; Fiber.yield(); } void ma

Re: Implement async/await using Fiber

2016-05-19 Thread Ali Çehreli via Digitalmars-d-learn
On 05/19/2016 04:42 PM, Ali Çehreli wrote: > You can use a delegate that takes a ref parameter: Correction: You can use a delegate that calls a function that takes a ref parameter. Ali

Re: Implement async/await using Fiber

2016-05-19 Thread Ali Çehreli via Digitalmars-d-learn
On 05/19/2016 12:57 PM, Yuxuan Shui wrote: I find this difficult because I can't passing data via Fiber.yield/Fiber.call pair. e.g. I want something like: void fiberFunc() { //Add some file descriptor to main loop string y = Fiber.yield(); writeln(y); } auto f = new Fiber(&fiberFunc

Implement async/await using Fiber

2016-05-19 Thread Yuxuan Shui via Digitalmars-d-learn
I find this difficult because I can't passing data via Fiber.yield/Fiber.call pair. e.g. I want something like: void fiberFunc() { //Add some file descriptor to main loop string y = Fiber.yield(); writeln(y); } auto f = new Fiber(&fiberFunc); f.call(); mainloop { if (fd_readable)