News for hackers. Stuff that matters.
Re:Sane Async Patterns in JavaScript by skylan_q on Thursday April 04, 2013 @01:32PM (#5493918)
While looking through the slides, I was wondering:

Is there some community-standard way of naming/declaring a JS function to let the programmer know just by reading the function's name that it will return a promise instead of a final computed value? I'm interested in knowing how people handle this. It's easy to forget that a function doesn't return a promise if the function name makes no mention of it, so I just make it explicit in the function name... but that's just how I handle it.

Re:Sane Async Patterns in JavaScript by vec on Thursday April 04, 2013 @05:21PM (#5495380)
I'm getting in the habit of letting the caller decide, something like the following:

    myAsyncFunc = function (param1, param2, callback) {
      var usingPromises = (callback === undefined);
      var returnVal = usingPromises ? Q.defer() : this;

      someFunction(function (err, res) {
        if (usingPromises) {
          err ? returnVal.reject(err) : returnVal.resolve(res);
        } else {
          callback(err, res);
        }
      });

      return returnVal;
    };
So if I call myAsyncFunc(foo, bar) it returns a promise and if I call myAsyncFunc(foo, bar, cb) it returns itself for chaining.
Re:Sane Async Patterns in JavaScript by tantalor on Thursday April 04, 2013 @01:57PM (#5494101)
Functions should be documented with the types of their parameters and return value.
Re:Sane Async Patterns in JavaScript by skylan_q on Thursday April 04, 2013 @02:54PM (#5494551)
I suppose I've just learned to really appreciate the "?" and "!" at the end of ruby function names...
Re:Sane Async Patterns in JavaScript by joshguthrie on Thursday April 04, 2013 @01:43PM (#5493989)
If that function is "supposed" to be async and its last argument is not something looking like "callback", there's a great chance it's a Promise.

Otherwise, there's no "naming scheme" for promise-based functions.