Created
February 7, 2017 14:00
-
-
Save alanshaw/491c885a62204eef4850dabdd27b73d0 to your computer and use it in GitHub Desktop.
Retry in watt, each retry adds a new stack frame
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
const watt = require("watt") | |
const send = watt(function* (next) { | |
try { | |
// oh noes, an err occurred | |
throw new Error('Unexpected things') | |
} catch (err) { | |
// Wait for a bit before retry | |
yield setTimeout(next) | |
return send() | |
} | |
return 42 | |
}) | |
// Eventually... | |
// FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory | |
send((err, res) => console.log(err, res)) | |
// No tail call recursion optimisation :( | |
// How to do this with generators? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment