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

I would write something like this:

  function handler(yes, no) {
      return function (err, data) {
          if (data) {
              yes(err, data);
          }
          else {
              no(err, data);
          }
      }
  }

  function get() {
      function done(err, data) {
  
          // do something with data
  
      }
      function db() {
          asynchronousDb.query("SELECT * fomr something where id = 3244", done);
      }
      asynchronousCache.get("id:3244", handler(done, db));
  }


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: