From acca21961b6351d4a8b89b72d66d77263a97c9d6 Mon Sep 17 00:00:00 2001 From: liushigit Date: Mon, 24 Jul 2017 20:18:10 +0800 Subject: [PATCH] Update promise.coroutine.md This is for this [issue](https://github.com/petkaantonov/bluebird/issues/1426) TODO: The `Promise` by the function returned by the `coroutine` method needs further explanation. A thorough understanding of [the code](https://github.com/petkaantonov/bluebird/blob/4f9093448f55ea76d5a8e090e42fe24b8e0da82c/src/generators.js#L191) is needed. --- docs/docs/api/promise.coroutine.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/api/promise.coroutine.md b/docs/docs/api/promise.coroutine.md index ff6e71256..24dd38020 100644 --- a/docs/docs/api/promise.coroutine.md +++ b/docs/docs/api/promise.coroutine.md @@ -13,7 +13,9 @@ title: Promise.coroutine Promise.coroutine(GeneratorFunction(...arguments) generatorFunction, Object options) -> function ``` -Returns a function that can use `yield` to yield promises. Control is returned back to the generator when the yielded promise settles. This can lead to less verbose code when doing lots of sequential async calls with minimal processing in between. Requires node.js 0.12+, io.js 1.0+ or Google Chrome 40+. +In a typical use case, the parameter `generatorFunction` should be a `GeneratorFunction` producing a generator that yields one or more `Promise`s. (Also see the Tips section below.) + +This method returns a function that returns a `Promise`(TODO: Elaborate this). When the returned function (e.g. the `ping` function in the example below) is called, it will start the generator (by calling its `next()`) and return immediately. Control is returned back to the generator when each yielded promise settles. This can lead to less verbose code when doing lots of sequential async calls with minimal processing in between. Requires node.js 0.12+, io.js 1.0+ or Google Chrome 40+. ```js var Promise = require("bluebird"); @@ -52,8 +54,6 @@ Running the example: Ping? 8 ... -When called, the coroutine function will start an instance of the generator and returns a promise for its final value. - Doing `Promise.coroutine` is almost like using the C# `async` keyword to mark the function, with `yield` working as the `await` keyword. Promises are somewhat like `Task`s. **Tip**