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
)

Parameters

path string

string repreesenting file path.

buffer void[]

data to be written to file.

callback void delegate
(
Exception
)
nothrow

a fuction called when operation finished or an error occurred.

Examples

import std.file : exists, readText, remove;
import dpromise.utils : runEventloop;
writeAsyncWithCallback("hoge.txt", "hogehogepiyopiyo", (e) nothrow {
  try {
    assert(e is null);
    assert(exists("hoge.txt"));
    assert(readText("hoge.txt") == "hogehogepiyopiyo");

    scope(exit) {
      remove("hoge.txt");
    }
  } catch(Exception e) {}
});

runEventloop();

Meta