writeAsyncWithCallback

Writes buffer to file path then calls the callback function with data as untyped array.

Creates a new file if it is not already exist. If an error occurred, the callback function will be called with the error.

nothrow @safe
void
writeAsyncWithCallback
(
string path
,
in void[] buffer
,
void delegate(
Exception
) nothrow
callback
)
in { assert (callback !is null); }

Parameters

path
Type: string

string repreesenting file path.

buffer
Type: void[]

data to be written to file.

callback
Type: void delegate(
Exception
) nothrow

a fuction called when operation finished or an error occurred.

Examples

1 import std.file : exists, readText, remove;
2 import dpromise.utils : runEventloop;
3 writeAsyncWithCallback("hoge.txt", "hogehogepiyopiyo", (e) nothrow {
4   try {
5     assert(e is null);
6     assert(exists("hoge.txt"));
7     assert(readText("hoge.txt") == "hogehogepiyopiyo");
8 
9     scope(exit) {
10       remove("hoge.txt");
11     }
12   } catch(Exception e) {}
13 });
14 
15 runEventloop();

Meta