Skip to content

Instantly share code, notes, and snippets.

View PetKatt's full-sized avatar

Piotr Wierciński PetKatt

View GitHub Profile
@PetKatt
PetKatt / gen-func.js
Created November 13, 2018 10:20
generator-function-es6
// 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
@PetKatt
PetKatt / promises-javascript.js
Created October 9, 2018 15:15
Promises in javascript - simulation of data fetching request
// 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);
@PetKatt
PetKatt / lazy-evaluation.js
Last active October 9, 2018 14:27
Lazy Evaluation in javascript by memoized version of call-by-name method
// 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);