Last active
August 29, 2015 14:07
-
-
Save SergeiGolos/f12ec6812fe93e1ef21a to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
/** | |
* @ngdoc service | |
* @name toPromiseApp.toPromise | |
* @description | |
* # toPromise | |
* # a service call for wrapping synchronous calls to result in a promise. | |
*/ | |
angular.module('toPromiseApp') | |
.factory('toPromise', [ | |
'$q', | |
'$timeout', | |
function ($q, $timeout) { | |
return function(arg) { | |
var fn = arg; | |
return function() { | |
var result = $q.defer(); | |
var applyArgs = arguments; | |
$timeout(function() { | |
result.resolve(Function.prototype.apply(fn, applyArgs)); | |
}, 0); | |
return result.promise; | |
} | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment