pavel's notebooks

  • Untitled - /pavel/coroutines-try-catch
    Last edited 7 years ago
    var Promise = require('bluebird') var waitForSeconds = Promise.coroutine(function *(secs) { yield new Promise(function(resolve, reject) { if (!secs || secs < 0) { reject(new Error('Stop that!')) } console.log('waiting ', secs, 'seconds') setTimeout(resolve, secs.) }) }) var run = Promise.coroutine(function *(secs) { //try{ yield waitForSeconds(secs); // } catch(e){ // console.log('INNER ERROR', e); //} }) run(10) .then(function() { console.log('DONE') }) .catch(function(e) { console.log('ERROR', e) })