Using an async buffer
Ali Çehreli
acehreli at yahoo.com
Fri Nov 8 01:12:37 UTC 2019
On 11/07/2019 07:07 AM, bioinfornatics wrote:
> Dear,
>
> I try to use the async buffer describe into std.parallelism
> documentation but my test code core dump!
I admit I don't fully understand the lifetime issues but removing the
"code smell" of the modul-level File object solved the issue for me,
which requires four changes:
// (1) Comment out the module-level variable
// File file;
// ...
@system
void next(File file, ref ubyte[] buf)
{
// (2.a) Use the parameter 'file'
// (2.b) Adjust the length of the buffer
// (rawRead may read less than the requested size)
buf = file.rawRead(buf);
}
// ...
// (3) Define a local variable
auto file = File(filePath, "rb");
// ...
// (4) Use "callables" that use the local 'file':
auto asyncReader = taskPool.asyncBuf((ref ubyte[] buf) =>
next(file, buf),
() => file.eof,
bufferSize);
Ali
More information about the Digitalmars-d-learn
mailing list