futurize

Transform js-style callbacks into tink_core Futures
https://github.com/kevinresol/futurize

To install, run:

haxelib install futurize 1.0.1 

See using Haxelib in Haxelib documentation for more information.

README.md

futurize

Transform js-style callbacks into tink_core Futures.

Usage

@:build(futurize.Futurize.build(":futurize"))
class AnyClass {
	public anyFunction() {
		var future = @:futurize functionWithJsStyleCallback($cb);
		future.handle(function(o) trace(o));
		
		// or without a future variable
		@:futurize functionWithJsStyleCallback($cb).handle(function(o) trace(o));
	}
	
	function functionWithJsStyleCallback(cb:String->String->Void) {
		cb('Error', null);
	}
}

Placeholders: - $cb0: callback that returns no data, i.e. function(err) {}. Transforms into a Surprise<Error, Noise> - $cb or $cb1: callback that returns one data, i.e. function(err, data) {}. Transforms into a Surprise<Error, T> - $cb2: callback that returns two data, i.e. function(err, data1, data2) {}. Transforms into a Surprise<Error, Pair<T1, T2>>

Custom handlers

@:build(futurize.Futurize.build(":futurize"), MyHandler)

class MyHandler {
	public static inline function cb0(e)
		return e == null ? Success(Noise) : Failure(e);
	
	public static inline function cb1(e, d)
		return e == null ? Success(d) : Failure(e);
	
	public static inline function cb2(e, d1, d2)
		return e == null ? Success(new Pair(d1, d2)) : Failure(e);
}
Contributors
kevinresol
Version
1.0.1
Published
2 years ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github