Skip to content

Instantly share code, notes, and snippets.

@alanshaw
Created February 7, 2017 14:00
Show Gist options
  • Save alanshaw/491c885a62204eef4850dabdd27b73d0 to your computer and use it in GitHub Desktop.
Save alanshaw/491c885a62204eef4850dabdd27b73d0 to your computer and use it in GitHub Desktop.
Retry in watt, each retry adds a new stack frame
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