Created
August 9, 2012 00:18
-
-
Save tony1223/3299930 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 以他的例子來說,*/ | |
| getThingFromHardDrive(function(thing) { | |
| uploadToServer(thing, function(response) { | |
| saveToLogDatabase(response, function(logResponse) { | |
| getAnotherThingFromHardDrive(function(thing) { | |
| // etc | |
| }) | |
| }) | |
| }) | |
| }) | |
| /* 可以串成 */ | |
| (function(){ | |
| var promise = new Promise(); | |
| getThingFromHardDrive(function(thing) { | |
| promise.resolve(thing); | |
| }) | |
| promise.then(function(thing){ | |
| var nextpromise = new Promise(); | |
| uploadToServer(thing, function(response) { | |
| nextpromise.resolve(response); | |
| }); | |
| return nextpromise; | |
| }).then(function(response){ | |
| var nextpromise = new Promise(); | |
| saveToLogDatabase(response, function(logResponse) { | |
| nextpromise.resolve(logResponse); | |
| }) | |
| return nextpromise; | |
| }).then(function(logResponse){ | |
| var nextpromise = new Promise(); | |
| getThingFromHardDrive(function(thing) { | |
| nextpromise.resolve(thing); | |
| }); | |
| return nextpromise; | |
| });; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment