You can also directly use Node.js style of API without binding if you need. We 
just use Task model with “async” builder. As I said, Wind.js supports different 
async model in parallel, you can choose whatever you prefer for each single 
async method, like the simple and stand Node.js model, Promise/A model or the 
Wind.js’s build-in Task model. The Task model just provides more features for 
common used async patterns (e.g., task cancellation).

Thanks
Jeffrey Zhao

From: Bruno Jouhier 
Sent: Friday, August 24, 2012 12:16 AM
To: [email protected] 
Subject: Re: [nodejs] Wind.js : An elegant approach to asynchronies JavaScript

If your EntityStore interface uses standard callbacks:

  EntityStore.prototype = {
    get: function(id, cb) { ... },
    save: function(entity, cb) { ... }
  };

Streamline will let you use it "as is". You will be able to write your 
wearEquipement function as:

  function wearEquipment(characterId, equipmentId, _) { 
    // code in synchronised style
    // for example:
    var users = new EntityStore('users');
    var user = users.get(userId, _);

  });

>From another streamline function you will call it as:

  var result = wearEquipment(characterId, equipementId, _);

And people who don't use streamline will also be able to call it, just like any 
other node.js async function (because the transformed function IS a standard 
node.js async function!):

  wearEquipment(characterId, equipmentId, function(err, result) {
    // usual node.js code here
  });

You do not have to introduce dual APIs with Async variants. You do not need any 
eval(Wind.compile('async', function(...) {...})) wrapper in every async 
function that you define, ... You get direct interoperability between 
streamlined code and regular node.js code.

Bruno

On Thursday, August 23, 2012 5:31:15 PM UTC+2, Tony Huang wrote: 
  I'm transforming my game server into Wind.js style. And it's really painless 
and smooth.

  Wind.js has already provided the Wind.Async.Bindings.fromStandard and 
Wind.Async.Bindings.fromCallback stubs to help you integrate existing codes.

  For instance, I already have a EntityStore class which provides standard 
style interface:
  EntityStore.prototype = {
    'get': function(cb) {
      //...
    },
    'save': function(entity,cb) {
      //...
     }
  };
  In order to make it usable in Wind.js, I just added following codes at the 
end of the module:
  ['get', 'save'].forEach(function(method) {
    EntityStore.prototype[method + 'Async'] = 
Wind.Async.Binding.fromStandard(EntityStore.prototype[method]);
  });

  As a result, I can access these methods in Wind.js easily in this way:

  var users = new EntityStore('user');
  var currentUser = $await(users.get(userId));

  It's quite easy.

  But in the other hand, Wind.js hasn't provide the reverse operation, so I 
added 2 method to the library:
  - Wind.Async.Binding.toStandard 
  - Wind.Async.Binding.toCallback

  So I can replace my code method by method without any overhead:
  My original code might be:
  function wearEquipment(characterId, equipmentId, cb) {
    //..... deep levels of callbacks
  }
  After refactoring, my code comes to:
  var wearEquipmentAsync = eval(Wind.compile('async', function(characterId, 
equipmentId) {
    // code in synchronised style
  });
  var wearEquipment = Wind.Async.Binding.toStandard(wearEquipmentAsync);

  Completely the same interface, the same function, but better-looking code.


  On Thu, Aug 23, 2012 at 12:55 AM, Bruno Jouhier <[email protected]> wrote:

    On Wednesday, August 22, 2012 12:55:41 PM UTC+2, Dominic wrote: 
      this is all very clever, but do code transformations really make 
callbacks easier?


    Take the streamline tutorial (doc: 
https://github.com/Sage/streamlinejs/blob/master/tutorial/tutorial.md source: 
https://github.com/Sage/streamlinejs/blob/master/tutorial/tuto7-parallel._js) 
and write it with plain callbacks.



    -- 
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to [email protected]
    To unsubscribe from this group, send email to
    [email protected]
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en





  -- 
  ------------------------------------------------------
  Tony Huang    [email protected]
                       [email protected]
                       [email protected]

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to