News for hackers. Stuff that matters.
Re:Pseudosynchronous JavaScript by kevincennis on Thursday June 25, 2015 @08:44AM (#9777432)
I'm a little unclear on this stuff:

  connection.call('collection', 'users');
Is `connection` a function? As in, you're essentially using Function#call and passing the string 'collection' as `thisArg`?

Or is `call` a custom method of whatever `connection` is an instance of?

I was under the impression from the article that `DatabaseClient` was just sort of an example, not a specific implementation of anything.

It seems like you're making some unusual assumptions about its API – unless I'm totally missing something.

Re:Pseudosynchronous JavaScript by renekooi on Thursday June 25, 2015 @09:35AM (#9777739)
`.call` is a method in some Promise libraries (eg. Bluebird). Basically,

    connection.call('collection', 'users')
is a shorthand for:

    connection.then(value => value.collection('users'))
Re:Pseudosynchronous JavaScript by csytan on Thursday June 25, 2015 @10:43AM (#9778204)
Thanks for clarifying. This is a very neat way of removing what would be an extra level of nesting.

It doesn't look like native promises support this unfortunately: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Another nitpick I have with native promises is that they require an extra level of nesting to get the resolve callback.

    // How it is now
    new Promise(function(resolve, reject) {
        resolve('done');
    });


    // vs. What most libraries implement
    var p = new Promise();
    p.resolve(function() {
        return 'done';
    });
Re:Pseudosynchronous JavaScript by inglor on Thursday June 25, 2015 @03:28PM (#9780358)
Both parts are incorrect, the native way is `Promise.resolve('done')`. As for .call - native promises let you subclass them. If you have a promise enabled environment you can use generators anyway. I used Q's syntax because that's what OP used.

Regardless - nice comment.