Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Consequences aren't executed asynchronously #54

Open
PierrotLL opened this issue Aug 31, 2017 · 1 comment
Open

Consequences aren't executed asynchronously #54

PierrotLL opened this issue Aug 31, 2017 · 1 comment

Comments

@PierrotLL
Copy link

In Consequence.execute, callbacks are executed one after the other. But if one of them adds a new callback in the queue, this new one will be executed during the same frame.
Repeat the same operation again and again, then you obtain an infinite loop that ends in error 1502.

The promises standards well say that onFulfilled should be executed the frame after deferred.resolve.

How to fix :
Use 2 callback queues, and do double-buffering. While the first queue is executed, new callbacks are pushed into the second queue, then the second queue is executed the next frame.

@PierrotLL PierrotLL reopened this Aug 31, 2017
@PierrotLL
Copy link
Author

PierrotLL commented Aug 31, 2017

Example:

var frameId:int = 0;
addEventListener(Event.ENTER_FRAME, function () : void {
	frameId++;
});

function foo() : Promise {
	trace(frameId);
	var d:Deferred = new Deferred();
	d.resolve(null);
	return d.promise.then(foo);
}
foo();

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant