Ignore:
Timestamp:
03/08/14 11:41:10 (11 years ago)
Author:
hendrikvanantwerpen
Message:

Update node modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/node_modules/q/README.md

    r484 r489  
    3535
    3636```javascript
    37 Q.fcall(step1)
    38 .then(step2)
    39 .then(step3)
    40 .then(step4)
     37Q.fcall(promisedStep1)
     38.then(promisedStep2)
     39.then(promisedStep3)
     40.then(promisedStep4)
    4141.then(function (value4) {
    4242    // Do something with value4
    43 }, function (error) {
    44     // Handle any error from step1 through step4
     43})
     44.catch(function (error) {
     45    // Handle any error from all above steps
    4546})
    4647.done();
    4748```
    4849
    49 With this approach, you also get implicit error propagation,
    50 just like ``try``, ``catch``, and ``finally``.  An error in
    51 ``step1`` will flow all the way to ``step5``, where it’s
    52 caught and handled.
     50With this approach, you also get implicit error propagation, just like `try`,
     51`catch`, and `finally`.  An error in `promisedStep1` will flow all the way to
     52the `catch` function, where it’s caught and handled.  (Here `promisedStepN` is
     53a version of `stepN` that returns a promise.)
    5354
    5455The callback approach is called an “inversion of control”.
     
    7778
    7879Q can exchange promises with jQuery, Dojo, When.js, WinJS, and more.
    79 Additionally, there are many libraries that produce and consume Q promises for
    80 everything from file system/database access or RPC to templating. For a list of
    81 some of the more popular ones, see [Libraries][].
    82 
    83 Please join the Q-Continuum [mailing list](https://groups.google.com/forum/#!forum/q-continuum).
    84 
     80
     81## Resources
     82
     83Our [wiki][] contains a number of useful resources, including:
     84
     85- A method-by-method [Q API reference][reference].
     86- A growing [examples gallery][examples], showing how Q can be used to make
     87  everything better. From XHR to database access to accessing the Flickr API,
     88  Q is there for you.
     89- There are many libraries that produce and consume Q promises for everything
     90  from file system/database access or RPC to templating. For a list of some of
     91  the more popular ones, see [Libraries][].
     92- If you want materials that introduce the promise concept generally, and the
     93  below tutorial isn't doing it for you, check out our collection of
     94  [presentations, blog posts, and podcasts][resources].
     95- A guide for those [coming from jQuery's `$.Deferred`][jquery].
     96
     97We'd also love to have you join the Q-Continuum [mailing list][].
     98
     99[wiki]: https://github.com/kriskowal/q/wiki
     100[reference]: https://github.com/kriskowal/q/wiki/API-Reference
     101[examples]: https://github.com/kriskowal/q/wiki/Examples-Gallery
    85102[Libraries]: https://github.com/kriskowal/q/wiki/Libraries
     103[resources]: https://github.com/kriskowal/q/wiki/General-Promise-Resources
     104[jquery]: https://github.com/kriskowal/q/wiki/Coming-from-jQuery
     105[mailing list]: https://groups.google.com/forum/#!forum/q-continuum
    86106
    87107
     
    109129guarantee when mentally tracing the flow of your code, namely that
    110130``then`` will always return before either handler is executed.
     131
     132In this tutorial, we begin with how to consume and work with promises. We'll
     133talk about how to create them, and thus create functions like
     134`promiseMeSomething` that return promises, [below](#the-beginning).
    111135
    112136
     
    321345var funcs = [foo, bar, baz, qux];
    322346
    323 var result = Q.resolve(initialVal);
     347var result = Q(initialVal);
    324348funcs.forEach(function (f) {
    325349    result = result.then(f);
     
    333357return funcs.reduce(function (soFar, f) {
    334358    return soFar.then(f);
    335 }, Q.resolve(initialVal));
     359}, Q(initialVal));
    336360```
    337361
     
    518542    var deferred = Q.defer();
    519543    Q.when(promise, deferred.resolve);
    520     Q.when(delay(ms), function () {
     544    delay(ms).then(function () {
    521545        deferred.reject(new Error("Timed out"));
    522546    });
     
    617641
    618642```javascript
    619 return Q.when($.ajax(...))
     643return Q($.ajax(...))
    620644.then(function () {
    621645});
     
    685709
    686710If you're working with functions that make use of the Node.js callback pattern,
    687 Q provides a few useful utility functions for converting between them. The
    688 most straightforward are probably `Q.nfcall` and `Q.nfapply` ("Node function
    689 call/apply") for calling Node.js-style functions and getting back a promise:
     711where callbacks are in the form of `function(err, result)`, Q provides a few
     712useful utility functions for converting between them. The most straightforward
     713are probably `Q.nfcall` and `Q.nfapply` ("Node function call/apply") for calling
     714Node.js-style functions and getting back a promise:
    690715
    691716```javascript
     
    776801to many users, you should probably keep it off. But in development, go for it!
    777802
    778 ## Reference
    779 
    780 A method-by-method [Q API reference][reference] is available on the wiki.
    781 
    782 [reference]: https://github.com/kriskowal/q/wiki/API-Reference
    783 
    784 ## More Examples
    785 
    786 A growing [examples gallery][examples] is available on the wiki, showing how Q
    787 can be used to make everything better. From XHR to database access to accessing
    788 the Flickr API, Q is there for you.
    789 
    790 [examples]: https://github.com/kriskowal/q/wiki/Examples-Gallery
    791 
    792803## Tests
    793804
     
    796807[tests]: https://rawgithub.com/kriskowal/q/master/spec/q-spec.html
    797808
    798 ---
    799 
    800 Copyright 2009-2012 Kristopher Michael Kowal
     809## License
     810
     811Copyright 2009–2013 Kristopher Michael Kowal
    801812MIT License (enclosed)
    802813
Note: See TracChangeset for help on using the changeset viewer.