readAsyncWithCallback

Read file path with asynchronous IO then calls the callback function. If file size is larger than up_to, only up_to bytes read.

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

  1. void readAsyncWithCallback(string path, size_t up_to, void delegate(void[], Exception) nothrow callback)
    nothrow @safe
    void
    readAsyncWithCallback
    (
    string path
    ,
    size_t up_to
    ,
    void delegate(
    void[]
    ,
    Exception
    ) nothrow
    callback
    )
    in { assert (callback !is null); }
  2. void readAsyncWithCallback(string path, void delegate(void[], Exception) nothrow callback)

Parameters

path
Type: string

string repreesenting file path.

up_to
Type: size_t

max buffer size. default value is size_t.max.

callback
Type: void delegate(
void[]
,
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 write("hoge.txt", "hogehogepiyopiyo");
4 scope(exit) remove("hoge.txt");
5 
6 readAsyncWithCallback("hoge.txt", size_t.max, (data, e) nothrow {
7   try {
8     assert(e is null);
9     assert(data !is null);
10 
11     assert(cast(string)data == "hogehogepiyopiyo");
12   } catch(Exception e) {}
13 });
14 
15 readAsyncWithCallback("hoge.txt", 8, (data, e) nothrow {
16   try {
17     assert(e is null);
18     assert(data !is null);
19 
20     assert(cast(string)data == "hogehoge");
21   } catch(Exception e) {}
22 });
23 
24 runEventloop();
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 readAsyncWithCallback("hoge.txt", (data, e) nothrow {
8   try {
9     assert(e is null);
10     assert(data !is null);
11 
12     assert(cast(string)data == "hogehogepiyopiyo");
13   } catch(Exception e) {}
14 });
15 
16 runEventloop();

Meta