Home

Awesome

Promise.gml

An adaptation of JavaScript Promises for GameMaker Studio 2.3+, based on this polyfill.

JS➜GML Equivalents

GameMaker does not allow using built-in function names as variable names, so:

Changes

GameMaker does not allow naming methods same as keywords, therefore:

Examples

Can also be found in the sample project, along with supporting scripts.

Basic (ft. custom setTimeout):

(new Promise(function(done, fail) {
	setTimeout(function(_done, _fail) {
		if (random(2) >= 1) _done("hello!"); else _fail("bye!");
	}, 250, done, fail);
})).andThen(function(_val) {
	trace("resolved!", _val);
}, function(_val) {
	trace("failed!", _val);
})

afterAll:

Promise.afterAll([
	Promise.resolve(3),
	42,
	new Promise(function(resolve, reject) {
		setTimeout(resolve, 100, "foo");
	})
]).andThen(function(values) {
	trace(values);
});

Chaining HTTP requests (ft. custom HTTP wrappers):

http_get_promise("https://yal.cc/ping").andThen(function(v) {
	trace("success", v);
	return http_get_promise("https://yal.cc/ping");
}).andThen(function(v) {
	trace("success2", v);
}).andCatch(function(e) {
	trace("failed", e);
})

Caveats