Skip to content

Commit

Permalink
justifying use of nextTick
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Alger committed Feb 25, 2014
1 parent 46b3e0e commit e608d29
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ define(function (require) {
// force a fetch of all datasources right now, optionally filter by type
Courier.prototype.fetch = function (onlyType) {
var courier = this;
// ensure that onFetch functions always run after the tick
// so that users can will be able to listen after or before the call to
// fetch and always get the same behavior (even if the onFetch runs synchronously)
nextTick(function () {
_.forOwn(onFetch, function (fn, type) {
if (onlyType && onlyType !== type) return;
Expand Down
1 change: 1 addition & 0 deletions src/courier/data_source/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ define(function (require) {
/* jshint eqeqeq: false */
return (!ref.fetchCount || !ref.version || ref.version != storedVersion);
});
// callbacks should always be called async
nextTick(cb, void 0, invalid);
};

Expand Down
3 changes: 2 additions & 1 deletion src/courier/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ define(function (require) {
*/
this.getFields = function (dataSource, callback) {
if (self.getFieldsFromObject(dataSource)) {
// If we already have the fields in our object, use that.
// If we already have the fields in our object, use that, but
// make sure we stay async
nextTick(callback, void 0, self.getFieldsFromObject(dataSource));
} else {
// Otherwise, try to get fields from Elasticsearch cache
Expand Down
2 changes: 1 addition & 1 deletion src/kibana/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ define(function (require) {

function _notify(fns, cur, prev) {
if ($rootScope.$$phase) {
// reschedule
// reschedule for next tick
nextTick(_notify, fns, cur, prev);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/kibana/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ define(function (require) {
function checkForCurrentConfigDoc(es, done) {
if (!kibanaIndexExists) return done();
console.log('checking if migration is necessary: not implemented');
// callbacks should always be called async
nextTick(done);
}

Expand Down

0 comments on commit e608d29

Please sign in to comment.