This file contains 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
// const fetch = require("node-fetch"); // npm install fetchAPI for Node.js | |
run(function*() { | |
const uri = 'https://jsonplaceholder.typicode.com/todos/1'; | |
const response = yield fetch(uri); // first stop | |
const resJSON = yield response.json(); // second stop | |
console.log(resJSON); | |
}); | |
// take care of the generator function |
This file contains 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
// SIMULATION OF A DATA FETCHING REQUEST WITH PROMISE | |
// Fulfilled Promise (data fetched successfully) | |
var promise1 = new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
resolve("Promise resolved"); | |
}, 300); | |
setTimeout(function() { | |
reject("Promise Rejected"); | |
}, 500); |
This file contains 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
// EAGER EVALUATION with RangeError on the var stream | |
function Stream(value) { | |
this.value = value; | |
this.next = new Stream(value + 1); | |
} | |
var stream = new Stream(10); | |
console.log(stream); |