readTextAsyncWithCallback

Read file path with asynchronous IO then calls the callback function with data as string(validate with std.utf.validate).

If an error occurred, the callback function will be called with the error.

nothrow @safe
void
readTextAsyncWithCallback
(
S = string
)
(
string path
,
void delegate
(
S
,
Exception
)
nothrow
callback
)
if (
isSomeString!S
)

Parameters

path string

string representing file path.

callback void delegate
(
S
,
Exception
)
nothrow

a fuction called when operation finished or an error occurred.

Examples

import std.file : write, remove;
import dpromise.utils : runEventloop;

write("hoge.txt", "hogehogepiyopiyo");
scope(exit) remove("hoge.txt");

readTextAsyncWithCallback!string("hoge.txt", (s, e) nothrow {
  assert(e is null);
  assert(s == "hogehogepiyopiyo");
});

runEventloop();

Meta