Skip to content

Instantly share code, notes, and snippets.

@ciembor
Created February 11, 2013 01:40
Show Gist options
  • Select an option

  • Save ciembor/4751901 to your computer and use it in GitHub Desktop.

Select an option

Save ciembor/4751901 to your computer and use it in GitHub Desktop.
Callback hell.
function refresh() {
chrome.windows.getAll(function(windows) {
for (var i = 0; i < windows.length; i++) {
chrome.tabs.getAllInWindow(windows[i].id, function(tabs) {
chrome.storage.sync.get('active', function(object) {
if (object.active !== undefined) {
for (var j = 0; j < tabs.length; j++) {
if (-1 !== object.active.indexOf(tabs[j].url)) {
chrome.tabs.reload(tabs[j].id);
}
}
}
});
});
}
});
}
@rezoner

rezoner commented Feb 11, 2013

Copy link
Copy Markdown

Dat way maybe?

function refresh() {

    function allWindowsCallback(windows) {
        for(var i = 0; i < windows.length; i++)
        chrome.tabs.getAllInWindow(windows[i].id, oneWindowCallback);
    }

    function oneWindowCallback(tabs) {
        chrome.storage.sync.get('active', function(object) {
            if(object.active !== undefined) for(var j = 0; j < tabs.length; j++)
            if(-1 !== object.active.indexOf(tabs[j].url)) chrome.tabs.reload(tabs[j].id);
        });
    }

    chrome.windows.getAll(allWindowsCallback);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment