Reputation: 42513
In chrome API for extensions lots of methods take "callback" argument. But for majority of methods it's not documented when callbacks are called. For example, chrome.tabs.remove
takes callback that reads:
If you specify the callback parameter, it should specify a function that looks like this:
function() {...};
This is all documentation i have. Given this documentation, how can i figure if callback will be called only once after all tabs are removed, or after each tab is removed? Based on the answer, i need to write different code. Maybe it's some "general" documentation sections about callback in chrome API, like "callbacks are always called once after operation is complete if otherwise is not specified". Or no one uses this API
and no one cares about documentation?
Upvotes: 0
Views: 2132
Reputation: 115950
From the Overview page:
Most methods in the chrome.* APIs are asynchronous: they return immediately, without waiting for the operation to finish. If you need to know the outcome of that operation, then you pass a callback function into the method.
The implied information here is that callbacks are called when information about the completed operation is available to be passed to the callback. When that is and exactly what information is available varies from operation to operation.
Callbacks are called once all of the relevant work has been done, so the tabs.remove
callback is called once all specified tabs are closed.
Upvotes: 5