Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Adapt wait interface into a hard API from events #1814

Closed
oliverfoster opened this issue Sep 27, 2017 · 0 comments
Closed

Turn Adapt wait interface into a hard API from events #1814

oliverfoster opened this issue Sep 27, 2017 · 0 comments
Assignees
Milestone

Comments

@oliverfoster
Copy link
Member

oliverfoster commented Sep 27, 2017

This arose from the naming of the callback event, "plugins:ready" - which suggests that the plugins are ready, singularly.

This mechanism is actually to stop adapt performing long blocking operations on initialization and navigation. Providing an interface to force Adapt to wait for asynchronous operations to take place before proceeding.

This idea is to turn:

Adapt.on("plugins:ready", function() {
    console.log("output3");
});
Adapt.trigger("plugin:beginWait");
_.defer(function() {
    console.log("output1");
    Adapt.trigger("plugin:endWait");
});
Adapt.on("plugins:ready", function() {
    console.log("output4");
});
Adapt.trigger("plugin:beginWait");
_.defer(function() {
    console.log("output2");
    Adapt.trigger("plugin:endWait");
});

Into:

Adapt.wait.queue(function() {
    console.log("output3");
});
Adapt.wait.for(function(end) {
    console.log("output1");
    end();
});
Adapt.wait.queue(function() {
    console.log("output4");
});
Adapt.wait.for(function(end) {
    console.log("output2");
    end();
});

Also included are:

Adapt.wait.isWaiting();

// Increments count for waiting queue
Adapt.wait.begin();

// Decrements count for waiting queue
Adapt.wait.end();

// Resolve asynchronously when the queue count is brought back to 0
Adapt.wait.queue(function() {

});

// Performs, begin, callback and end
Adapt.wait.for(function(end) {  
    end();  
});
@oliverfoster oliverfoster self-assigned this Sep 27, 2017
@oliverfoster oliverfoster changed the title turn wait interface into hard api Turn Adapt wait interface into a hard API from events Sep 27, 2017
@moloko moloko added this to the Adapt v3 milestone Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants