www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Task when used on a function that takes parameters doesnt work.

reply Ruby The Roobster <michaeleverestc79 gmail.com> writes:
Here is a test that I did:

void func(int i)
{
Thread.sleep(i.seconds);
}
void main() {
auto test = Task!func(3);
test.executeInNewThread();
test.yeildForce();
}

This gives the following errors(I'm using Code::Blocks as an IDE 
by the way, so this is what the IDE outputted):
d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error:
function `hello.func(int i)` is not callable using argument types `()`|

d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|      


hello.d|8|Error: template instance `std.parallelism.Task!(func)` 
error instantiating|


Any fix for this?
Nov 12 2020
next sibling parent reply Daniel Kozak <kozzi11 gmail.com> writes:
On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn <
digitalmars-d-learn puremagic.com> wrote:

 Here is a test that I did:

 void func(int i)
 {
 Thread.sleep(i.seconds);
 }
 void main() {
 auto test = Task!func(3);
 test.executeInNewThread();
 test.yeildForce();
 }

 This gives the following errors(I'm using Code::Blocks as an IDE
 by the way, so this is what the IDE outputted):
 d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error:
 function `hello.func(int i)` is not callable using argument types `()`|

 d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|


 hello.d|8|Error: template instance `std.parallelism.Task!(func)`
 error instantiating|


 Any fix for this?
You have some typos there import core.thread; import std.parallelism; void func(int i) { Thread.sleep(i.seconds); } void main() { auto test = task!(func)(3); test.executeInNewThread(); test.yieldForce(); }
Nov 12 2020
parent Ruby The Roobster <michaeleverestc79 gmail.com> writes:
On Thursday, 12 November 2020 at 15:12:55 UTC, Daniel Kozak wrote:
[...]
Thanks.
Nov 12 2020
prev sibling parent Daniel Kozak <kozzi11 gmail.com> writes:
On Thu, Nov 12, 2020 at 4:12 PM Daniel Kozak <kozzi11 gmail.com> wrote:

 On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn <
 digitalmars-d-learn puremagic.com> wrote:

 Here is a test that I did:

 void func(int i)
 {
 Thread.sleep(i.seconds);
 }
 void main() {
 auto test = Task!func(3);
 test.executeInNewThread();
 test.yeildForce();
 }

 This gives the following errors(I'm using Code::Blocks as an IDE
 by the way, so this is what the IDE outputted):
 d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error:
 function `hello.func(int i)` is not callable using argument types `()`|

 d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|


 hello.d|8|Error: template instance `std.parallelism.Task!(func)`
 error instantiating|


 Any fix for this?
You have some typos there import core.thread; import std.parallelism; void func(int i) { Thread.sleep(i.seconds); } void main() { auto test = task!(func)(3); test.executeInNewThread(); test.yieldForce(); }
Typos: instead of Task you should write task, instead of yeildForce you should write yieldForce
Nov 12 2020