// Read two files in at the same time again, // but this time use a function pointer instead // of an alias to represent std.file.read. import std.file; void main() { // Create and execute a Task for reading // foo.txt. auto file1Task = task(&read!string, "foo.txt", size_t.max); file1Task.executeInNewThread(); // Read bar.txt in parallel. auto file2Data = read("bar.txt"); // Get the results of reading foo.txt. auto file1Data = file1Task.yieldForce; }
Notes: This function takes a non-scope delegate, meaning it can be used with closures. If you can't allocate a closure due to objects on the stack that have scoped destruction, see scopedTask, which takes a scope delegate.
Creates a Task on the GC heap that calls a function pointer, delegate, or class/struct with overloaded opCall.