This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(*): implement more granular pending task tracking #16603
Closed
gkalpak
wants to merge
13
commits into
angular:master
from
gkalpak:feat-granular-pending-task-tracking
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b0a28d9
feat(*): implement more granular pending task tracking
gkalpak 5d68b93
fixup! feat(*): implement more granular pending task tracking
gkalpak fbbaf89
fixup! feat(*): implement more granular pending task tracking
gkalpak d39460f
refactor(ngMock/$interval): more closely follow actual `$interval`'s …
gkalpak a446203
refactor($interval): share code between `$interval` and `ngMock/$inte…
gkalpak fd4f707
refactor($browser): share task-tracking code between `$browser` and `…
gkalpak ef5f6f7
feat(ngMock): add `$flushPendingTasks()` and `$verifyNoPendingTasks()`
gkalpak 2c78686
fixup! feat(ngMock): add `$flushPendingTasks()` and `$verifyNoPending…
gkalpak 2d498a3
docs(ngMock/$timeout): recommend `$verifyNoPendingTasks()` when appro…
gkalpak 5527335
docs(ngMock/$timeout): deprecate `flush()` and `verifyNoPendingTasks()`
gkalpak 8dfd9d9
fixup! feat(ngMock): add `$flushPendingTasks()` and `$verifyNoPending…
gkalpak e93405d
fixup! feat(*): implement more granular pending task tracking
gkalpak 86b0c03
fixup! refactor($browser): share task-tracking code between `$browser…
gkalpak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,18 @@ var $intervalMinErr = minErr('$interval'); | |
|
||
/** @this */ | ||
function $IntervalProvider() { | ||
this.$get = ['$rootScope', '$window', '$q', '$$q', '$browser', | ||
function($rootScope, $window, $q, $$q, $browser) { | ||
this.$get = ['$$intervalFactory', '$window', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume we don't care that this is "breaking" the decoration of $interval by including a private service? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it break it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that you ask ... doesn't look like it breaks anything (and it relied on a private service before) |
||
function($$intervalFactory, $window) { | ||
var intervals = {}; | ||
|
||
var setIntervalFn = function(tick, delay, deferred) { | ||
var id = $window.setInterval(tick, delay); | ||
intervals[id] = deferred; | ||
return id; | ||
}; | ||
var clearIntervalFn = function(id) { | ||
$window.clearInterval(id); | ||
delete intervals[id]; | ||
}; | ||
|
||
/** | ||
* @ngdoc service | ||
|
@@ -135,49 +143,7 @@ function $IntervalProvider() { | |
* </file> | ||
* </example> | ||
*/ | ||
function interval(fn, delay, count, invokeApply) { | ||
var hasParams = arguments.length > 4, | ||
args = hasParams ? sliceArgs(arguments, 4) : [], | ||
setInterval = $window.setInterval, | ||
clearInterval = $window.clearInterval, | ||
iteration = 0, | ||
skipApply = (isDefined(invokeApply) && !invokeApply), | ||
deferred = (skipApply ? $$q : $q).defer(), | ||
promise = deferred.promise; | ||
|
||
count = isDefined(count) ? count : 0; | ||
|
||
promise.$$intervalId = setInterval(function tick() { | ||
if (skipApply) { | ||
$browser.defer(callback); | ||
} else { | ||
$rootScope.$evalAsync(callback); | ||
} | ||
deferred.notify(iteration++); | ||
|
||
if (count > 0 && iteration >= count) { | ||
deferred.resolve(iteration); | ||
clearInterval(promise.$$intervalId); | ||
delete intervals[promise.$$intervalId]; | ||
} | ||
|
||
if (!skipApply) $rootScope.$apply(); | ||
|
||
}, delay); | ||
|
||
intervals[promise.$$intervalId] = deferred; | ||
|
||
return promise; | ||
|
||
function callback() { | ||
if (!hasParams) { | ||
fn(iteration); | ||
} else { | ||
fn.apply(null, args); | ||
} | ||
} | ||
} | ||
|
||
var interval = $$intervalFactory(setIntervalFn, clearIntervalFn); | ||
|
||
/** | ||
* @ngdoc method | ||
|
@@ -205,8 +171,7 @@ function $IntervalProvider() { | |
// Interval cancels should not report an unhandled promise. | ||
markQExceptionHandled(deferred.promise); | ||
deferred.reject('canceled'); | ||
$window.clearInterval(id); | ||
delete intervals[id]; | ||
clearIntervalFn(id); | ||
|
||
return true; | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
/** @this */ | ||
function $$IntervalFactoryProvider() { | ||
this.$get = ['$browser', '$q', '$$q', '$rootScope', | ||
function($browser, $q, $$q, $rootScope) { | ||
return function intervalFactory(setIntervalFn, clearIntervalFn) { | ||
return function intervalFn(fn, delay, count, invokeApply) { | ||
var hasParams = arguments.length > 4, | ||
args = hasParams ? sliceArgs(arguments, 4) : [], | ||
iteration = 0, | ||
skipApply = isDefined(invokeApply) && !invokeApply, | ||
deferred = (skipApply ? $$q : $q).defer(), | ||
promise = deferred.promise; | ||
|
||
count = isDefined(count) ? count : 0; | ||
|
||
function callback() { | ||
if (!hasParams) { | ||
fn(iteration); | ||
} else { | ||
fn.apply(null, args); | ||
} | ||
} | ||
|
||
function tick() { | ||
if (skipApply) { | ||
$browser.defer(callback); | ||
} else { | ||
$rootScope.$evalAsync(callback); | ||
} | ||
deferred.notify(iteration++); | ||
|
||
if (count > 0 && iteration >= count) { | ||
deferred.resolve(iteration); | ||
clearIntervalFn(promise.$$intervalId); | ||
} | ||
|
||
if (!skipApply) $rootScope.$apply(); | ||
} | ||
|
||
promise.$$intervalId = setIntervalFn(tick, delay, deferred, skipApply); | ||
|
||
return promise; | ||
}; | ||
}; | ||
}]; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably a bit late for this TODO now :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope never dies 😃