You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Henrique Mendonça (JIRA)" <ji...@apache.org> on 2014/02/23 20:21:20 UTC

[jira] [Comment Edited] (THRIFT-2376) nodejs: allow Promise style calls for client and server

    [ https://issues.apache.org/jira/browse/THRIFT-2376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13909831#comment-13909831 ] 

Henrique Mendonça edited comment on THRIFT-2376 at 2/23/14 7:19 PM:
--------------------------------------------------------------------

This is awesome Pierre! Thanks a lot for the patch.
"Q" seems to still be the most popular implementation by far.
What do you think about using nodeify() or denodeify() so we don't need two copies of the test handlers and drivers?

Edit: I'm committing it as it is anyway, maybe we should really test it independently. However, if you have a good idea feel free to share it with us ;)

Cheers,
Henrique


was (Author: henrique):
This is awesome Pierre! Thanks a lot for the patch.
"Q" seems to still be the most popular implementation by far.
What do you think about using nodeify() or denodeify() so we don't need two copies of the test handlers and drivers?

Cheers,
Henrique

> nodejs: allow Promise style calls for client and server
> -------------------------------------------------------
>
>                 Key: THRIFT-2376
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2376
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Node.js - Compiler
>    Affects Versions: 0.9.2
>            Reporter: Pierre Lamot
>            Assignee: Henrique Mendonça
>             Fix For: 0.9.2
>
>         Attachments: 0001-THRIFT-2376-nodejs-allow-Promise-style-calls-for-cli.patch
>
>
> the idea of this patch is to allow writing server functions and clients calls using future/promise style.
> for instance a server function:
> {code:javascript}
> {
>   divide: function(n1, n2, result) {
>     if (n2 === 0) {
>       var x = new ttypes.InvalidOperation();
>       result(x);
>       return;
>     }
>     result(null, n1/n2);
>   }
> }
> {code}
> might be written as:
> {code:javascript}
> {
>   divide: function(n1, n2) {
>     if (n2 === 0) {
>       throw new ttypes.InvalidOperation();
>     }
>     return n1/n2;
>   }
> }
> {code}
> both style remains valid, the style to use is detected according to the function signature (is there a last argument for the callback). 
> when using promise style, a promise can also be return in stead of the result for asynchronous results.
> the client side might use promise as well:
> {code:javascript}
> client.calculate(1, work, function(err, message) {
>   if (err) {
>     console.log("InvalidOperation " + err);
>   } else {
>     console.log('Whoa? You know how to divide by zero?');
>   }
> });
> {code}
> might be written as:
> {code:javascript}
> client.calculate(1, work)
>   .then(function(message) {
>         console.log('Whoa? You know how to divide by zero?');
>   })
>   .fail(function(err) {
>     console.log("InvalidOperation " + err);
>   });
> {code}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)