Skip to content

Instantly share code, notes, and snippets.

View elsangedy's full-sized avatar
🚀

Munir Ahmed Elsangedy elsangedy

🚀
View GitHub Profile
@elsangedy
elsangedy / recursive.js
Last active April 19, 2018 13:01
Recursive function to execute function until attempts finish or promise resolve
const waitFor = (delay = 0) => new Promise((resolve) => setTimeout(resolve, delay))
const recursiveToZero = (func, attempt, delay, error) => {
if (attempt === 0) {
throw error || new Error('Fail')
}
return func().catch((err) => waitFor(delay).then(() => recursiveToZero(func, attempt - 1, delay, err)))
}
@elsangedy
elsangedy / app.js
Last active August 29, 2015 14:26
SPA
var app = (function() {
var App = function() {
var _modules = {
controllers: {},
directives: {},
constants: {},
services: {},
routes: {}
};