Since they are samples of “async” builders. :)

We can use fs.mkdir, fs.readdir directly with another builder. Of couse the 
Task object can be used as conitnuation callback (since everything is normal 
JavaSript):

xxxAsync().on(“complete”, function () { console.log(this.result); }).start();

There’s no recompilation during the execution. There’s only one compilation and 
eval for each single method definition.

Thanks
Jeffrey Zhao

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

Not sure I get it. From your samples 
(https://github.com/JeffreyZhao/wind/blob/master/samples/async/node/copy-dir.js),
 you need to wrap node's APIs:


fs.existsAsync = Binding.fromCallback(fs.exists);fs.mkdirAsync = 
Binding.fromStandard(fs.mkdir);fs.readdirAsync = 
Binding.fromStandard(fs.readdir);fs.statAsync = 
Binding.fromStandard(fs.stat);fs.closeAsync = 
Binding.fromStandard(fs.close);fs.openAsync = 
Binding.fromStandard(fs.open);fs.readAsync = 
Binding.fromStandard(fs.read);fs.writeAsync = Binding.fromStandard(fs.write); 
With streamline you don't (except for exists which is a black swan :-( ). You 
can directly call fs.mkdir, fs.readdir, etc.

Also, the xxxAsync functions that you write in Wind style return an instance of 
Task and you run them with a start call, as xxxAsync(args).start(). Can you 
call these functions from non-Wind code, with a continuation callback? 
Something like xxxAsync(args).start(cb);

Also, you need an  eval(Wind.compile('async', function(...) {...}))  wrapper 
around every async function that you define. This means that you are going to 
compile and eval every time you create a new closure at runtime. You can 
probably avoid the recompile (by caching it) but not the eval. Is this right?

Consider

  function f1(x) {
    return eval(Wind.compile('async', function(...) { var y = $await(f2()); 
return f3(x, y); });
  }


Bruno



On Thursday, August 23, 2012 6:34:45 PM UTC+2, Jeffrey Zhao wrote: 
  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

-- 
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