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
)
in { assert (callback !is null); }

Parameters

path
Type: string

string representing file path.

callback
Type: void delegate(
S
,
Exception
) nothrow

a fuction called when operation finished or an error occurred.

Examples

1 import std.file : write, remove;
2 import dpromise.utils : runEventloop;
3 
4 write("hoge.txt", "hogehogepiyopiyo");
5 scope(exit) remove("hoge.txt");
6 
7 readTextAsyncWithCallback!string("hoge.txt", (s, e) nothrow {
8   assert(e is null);
9   assert(s == "hogehogepiyopiyo");
10 });
11 
12 runEventloop();

Meta