Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is what I mean. The code that uses the callbacks go first, the callbacks themselves are all named and access to closures withstanding, not nested.

      // this is all the code that is used,
      var _changes = follow(couchOpts);
      _changes.on('change', onChange);
      _changes.on('error', onError);
      _changes.resume();
  
      // from here is just named functions
      function onChange(data) {
        _changes.pause();
        save(data.seqId, saveFn);
      }
      
      function saveFn(err, entity) {
        if (err) { return console.log(err); }
        _changes.resume();
      }
      
      function onError(err) {
        console.log(err);
      }


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: