Last active
February 28, 2017 11:12
-
-
Save punkbit/e0843f6ce54d57aa61b52223fb68fcde to your computer and use it in GitHub Desktop.
Revisions
-
punkbit revised this gist
Feb 28, 2017 . 1 changed file with 3 additions and 3 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ let global = { stop: false } const timedCaller = (params) => { params.debug && console.log('[DEBUG ' + params.name + '] fn call') // Test condition, if true run the callback if (params.condition.test()) { @@ -24,7 +24,7 @@ const timeCaller = (params) => { params.setCallback() } params.debug && console.log('[DEBUG ' + params.name + '] should recall / recursive') timedCaller(params) }, params.time.retryAfterMs) } else { params.debug && console.log('[DEBUG ' + params.name + '] timeout exceeded') @@ -35,7 +35,7 @@ const timeCaller = (params) => { } } timedCaller({ name: 'fnFoobar', time: { start: new Date().getTime(), -
punkbit revised this gist
Feb 28, 2017 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -35,7 +35,7 @@ const timeCaller = (params) => { } } timeCaller({ name: 'fnFoobar', time: { start: new Date().getTime(), -
punkbit revised this gist
Feb 28, 2017 . 1 changed file with 2 additions and 2 deletions.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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ let global = { stop: false } const timeCaller = (params) => { params.debug && console.log('[DEBUG ' + params.name + '] fn call') // Test condition, if true run the callback if (params.condition.test()) { @@ -24,7 +24,7 @@ const caller = (params) => { params.setCallback() } params.debug && console.log('[DEBUG ' + params.name + '] should recall / recursive') timeCaller(params) }, params.time.retryAfterMs) } else { params.debug && console.log('[DEBUG ' + params.name + '] timeout exceeded') -
punkbit renamed this gist
Feb 28, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
punkbit created this gist
Feb 28, 2017 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ let global = { stop: false } const caller = (params) => { params.debug && console.log('[DEBUG ' + params.name + '] fn call') // Test condition, if true run the callback if (params.condition.test()) { params.debug && console.log('[DEBUG ' + params.name + '] condition test passed!') if (typeof params.condition.callback === 'function') { params.debug && console.log('[DEBUG ' + params.name + '] callback is fn, should call!') return params.condition.callback() } } // Keep trying as long it does not exceed max timeout params.time.end = new Date().getTime() params.time.totalMs = params.time.end - params.time.start params.debug && console.log('[DEBUG ' + params.name + '] update params.time: ', params.time) if (params.time.totalMs < params.time.maxMs) { params.debug && console.log('[DEBUG ' + params.name + '] did not exceed total timeout') params.timeout = setTimeout(() => { clearTimeout(params.timeout) if (typeof params.stepCallback === 'function') { params.debug && console.log('[DEBUG ' + params.name + '] has a stepCallback and should call') params.setCallback() } params.debug && console.log('[DEBUG ' + params.name + '] should recall / recursive') caller(params) }, params.time.retryAfterMs) } else { params.debug && console.log('[DEBUG ' + params.name + '] timeout exceeded') if (typeof params.time.exceedMaxTimeCallback === 'function') { params.debug && console.log('[DEBUG ' + params.name + '] has exceedMaxTimeCallback and should call') params.time.exceedMaxTimeCallback() } } } caller({ name: 'fnFoobar', time: { start: new Date().getTime(), end: 0, totalMs: 0, maxMs:10000, retryAfterMs: 1000, exceedMaxTimeCallback: () => { console.log('The caller exceedMaxTimeout!') } }, condition: { test: () => (global && global.stop), callback: () => { console.log('Hello world!') } }, debug: true }) console.log('global.stop: ', global.stop) setTimeout(() => { global.stop = true console.log('global.stop: ', global.stop) }, 5000)