Promise<Void>

163 views
Skip to first unread message

David Mouton

unread,
Sep 22, 2017, 3:27:43 AM9/22/17
to Haxe
Hi,
I want to make a Promize without pamameter or value.
Actually i use a Bool as a value

private var _resolve:Bool->Void;
private var _reject:Bool->Void;

public function new() {
_cache = new AssetLoaderCache();
}

public function load(url:AssetURL):Promise<Bool> {
_url = url;
_asset = _cache.getLoadingAsset(_url);

return new Promise(loadPromise);
}

private function loadPromise(resolve:Bool->Void,reject:Bool->Void):Void{
_resolve = resolve;
_reject = reject;
_resolve(true);
}


But i just want to call _resolve();
I dont need a boolean at all.

Any idea ?

Thanks

Franco Ponticelli

unread,
Sep 22, 2017, 9:22:03 AM9/22/17
to Haxe
In thx we have a type `thx.Unit` whose only inhabitant is `unit`. That is the kind of type/value you want to use in these situations. Historically we use `thx.Nil` in `thx.Promise` but `Unit` is just a better name.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Yaroslav Sivakov

unread,
Sep 26, 2017, 4:33:31 AM9/26/17
to Haxe
My solution: use `Promise<{}>` and `resolve(null)`.

пятница, 22 сентября 2017 г., 10:27:43 UTC+3 пользователь David Mouton написал:

David Mouton

unread,
Sep 29, 2017, 3:17:49 AM9/29/17
to Haxe
Thank you, but it's not better than a Promise<Bool> and resolve(true)
Reply all
Reply to author
Forward
0 new messages