A callback. All callbacks in the standard library are functions which accept two arguments: an error (haxe.Error) and a result (T). If error is non-null, result must be null. The callback type is declared in CallbackData.

This abstract defines multiple @:from conversions to improve readability of callback code.

Static methods

@:fromstaticinlinefromErrorOnly (f:Error ‑> Void):Callback<NoData>

Wraps a function which takes a single haxe.Error argument into a callback of type Callback<NoData>. Allows:

var cb:Callback<NoData> = (err) -> trace("error!", err);

@:fromstaticinlinefromErrorResult<T> (f:Error ‑> T ‑> Void):Callback<T>

Wraps a callback function declared without ? (optional) arguments into a callback.

@:fromstaticinlinefromOptionalErrorOnly (f:Error ‑> Void):Callback<NoData>

Wraps a function which takes a single optional haxe.Error argument into a callback of type Callback<NoData>. Allows:

var cb:Callback<NoData> = (?err) -> trace("error!", err);

staticnonNull<T> (?cb:Callback<T>):Callback<T>

Returns a callback of the same type as cb which is guaranteed to be non-null. If cb is given and is not null it is returned directly. If cb is null a dummy callback which does nothing is returned instead.