async.js 731 B

12345678910111213141516171819202122232425262728293031
  1. const angular = require('angular')
  2. const mod = angular.module('async', [])
  3. mod.run(($q, $window, $rootScope) => {
  4. let timer = null
  5. const then = $q.prototype.then
  6. const setTimer = () => {
  7. if (!timer) {
  8. timer = setTimeout(() => {
  9. timer = null
  10. $rootScope.$digest()
  11. })
  12. }
  13. }
  14. $q.prototype.then = function(successCallback, errorCallback, notifyCallback) {
  15. return then.call(
  16. this,
  17. successCallback && (val => {
  18. setTimer()
  19. return successCallback(val)
  20. }),
  21. errorCallback && (err => {
  22. setTimer()
  23. return errorCallback(err)
  24. }),
  25. notifyCallback && (msg => {
  26. setTimer()
  27. return errorCallback(err)
  28. })
  29. )
  30. }
  31. })