digitalmars.D.learn - How create a function that receive a function and run it in another
- Marcone (14/14) Dec 26 2019 import std;
- mipri (10/24) Dec 26 2019 This works:
- Marcone (9/39) Dec 27 2019 Very Good! Thank you:
- Alexandru Ermicioi (6/36) Dec 30 2019 or you can use just
import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in other threading, but I get this error bellow. How can I get success? Error: static function Programa.threading.Task!(fun).Task.impl cannot access frame of function Programa.threading Error: template instance `Programa.threading.Task!(fun)` error instantiating
Dec 26 2019
On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote:import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in other threading, but I get this error bellow. How can I get success? Error: static function Programa.threading.Task!(fun).Task.impl cannot access frame of function Programa.threading Error: template instance `Programa.threading.Task!(fun)` error instantiatingThis works: import std; import core.thread; auto threading(void function() fun){ return task(fun).executeInNewThread(); } void main(){ writeln("Main: ", thisTid); threading({ writeln("Hello, ", thisTid); }); }
Dec 26 2019
On Friday, 27 December 2019 at 07:06:52 UTC, mipri wrote:On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote:Very Good! Thank you: import std; import core.thread; alias threading = compose!(fun => fun.executeInNewThread(), fun => task(fun)); void main(){ threading({writeln("Ola Mundo!");}); }import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in other threading, but I get this error bellow. How can I get success? Error: static function Programa.threading.Task!(fun).Task.impl cannot access frame of function Programa.threading Error: template instance `Programa.threading.Task!(fun)` error instantiatingThis works: import std; import core.thread; auto threading(void function() fun){ return task(fun).executeInNewThread(); } void main(){ writeln("Main: ", thisTid); threading({ writeln("Hello, ", thisTid); }); }
Dec 27 2019
On Friday, 27 December 2019 at 07:06:52 UTC, mipri wrote:On Friday, 27 December 2019 at 06:08:16 UTC, Marcone wrote:or you can use just https://dlang.org/library/std/concurrency/spawn.html from std.concurrency to avoid needless bike construction. Best regards, Alexandru.import std; import core.thread; auto threading(lazy void fun){ return task!fun().executeInNewThread(); } void main(){ threading(writeln("Hello World!")); } I want to create a function threading() to run some function in other threading, but I get this error bellow. How can I get success? Error: static function Programa.threading.Task!(fun).Task.impl cannot access frame of function Programa.threading Error: template instance `Programa.threading.Task!(fun)` error instantiatingThis works: import std; import core.thread; auto threading(void function() fun){ return task(fun).executeInNewThread(); } void main(){ writeln("Main: ", thisTid); threading({ writeln("Hello, ", thisTid); }); }
Dec 30 2019