Skip to content

Instantly share code, notes, and snippets.

Piotr Wierciński PetKatt

Block or report user

Report or block PetKatt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@PetKatt
PetKatt / gen-func.js
Created Nov 13, 2018
generator-function-es6
View gen-func.js
// 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 Oct 9, 2018
Promises in javascript - simulation of data fetching request
View promises-javascript.js
// 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 Oct 9, 2018
Lazy Evaluation in javascript by memoized version of call-by-name method
View lazy-evaluation.js
// 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);
You can’t perform that action at this time.