Promise

作者: 莫名FCJ | 来源:发表于2017-10-25 16:25 被阅读6次

代码:https://github.com/fengchunjian/nodejs_examples/tree/master/promise

Promise01

npm install node-fetch -g

//promise01.js
var fetch = require("node-fetch");
fetch("https://api.github.com")
.then(function(res) {
    return res.json();
}).then(function(json) {
    console.log(json);
});

Promise02

//promise02.js
unction fetchPage() {
    console.log("fetchPage");
    return new Promise(function(resolve, reject) {
        setTimeout(function() {
            resolve("Page data");
        }, 1000);
    });
}

fetchPage().then(function(data) {
    console.log(data);
});

参考文档

Pormise
http://edu.51cto.com/center/course/lesson/index?id=169729
初探Promise
https://segmentfault.com/a/1190000007032448

相关文章

网友评论

      本文标题:Promise

      本文链接:https://www.haomeiwen.com/subject/mcoqpxtx.html