Skip to content

Instantly share code, notes, and snippets.

View gskachkov's full-sized avatar

Oleksander Skachkov gskachkov

  • Itera Consulting
  • Ukraine, Kiev
View GitHub Profile
@gskachkov
gskachkov / Promise.all.js
Last active July 16, 2017 21:28
Example of usage Promise.all
var getPromise = (value, delay) => {
return new Promise(resolve => {
setTimeout(() => resolve(value), delay);
});
};
var promise1 = getPromise('value-1', 150);
var promise2 = getPromise('value-2', 250);
var promise3 = getPromise('value-3', 50);
@gskachkov
gskachkov / Promise.race.js
Created March 6, 2017 19:40
Example of usage Promise.race
var getPromise = (value, delay) => {
return new Promise(resolve => {
setTimeout(() => resolve(value), delay);
});
};
var promise1 = getPromise('value-1', 350);
var promise2 = getPromise('value-2', 250);
var promise3 = getPromise('value-3', 150);
  • Overview of nonlinear control flow in javascript
  • Async function
    • Syntax(function, method, async arrow function expression)
    • Runtime -> Diagram how it works…
    • Examples
    • Use Symbols.Async
  • Using await
  • Using promises
    • Promise all
  • Promise race
@gskachkov
gskachkov / async.function.declaration.js
Last active April 19, 2017 09:59
Example of the declaration async function
async function foo () {
const result = await fetch("https://randomuser.me/api/?results=10", { method: "GET" });
return result;
}
async function bar() {
console.log(await foo());
};
bar();
@gskachkov
gskachkov / js
Last active April 17, 2017 18:07
Small test of proto
class SuperClass {
constructor() {
print('SuperClass constructor')
}
}
let ProxiedSuperClass = new Proxy(SuperClass, {});
class A extends ProxiedSuperClass {
constructor() {
@gskachkov
gskachkov / async.function.declaration.js
Created May 9, 2017 14:06
Async function declaration
async function foo () {
const result = await fetch("https://randomuser.me/api/?results=10", { method: "GET" });
return result;
}
const boo = async function () {
return await fetch("https://randomuser.me/api/?results=10", { method: "GET" });
};
foo();
@gskachkov
gskachkov / async.function.await-non-promise-value.js
Created May 10, 2017 09:34
Order of async function execution
const foo = async function () {
console.log('before await');
const value = await 'boo';
console.log('after await');
return value;
};
console.log('before async invocation');
foo();
console.log('after async invocation');
@gskachkov
gskachkov / async.await.reject.promise.js
Last active March 5, 2019 10:20
Await rejected promise
var foo = async function () {
try {
await Promise.reject('error in promise');
} catch (e) {
console.log('caught error:', e);
}
};
foo().then(
result => console.log('success-', result),
@gskachkov
gskachkov / async.function.as-plain-function.js
Last active June 3, 2017 09:51
Async function as plain function
async function foo(args) {
console.log('before await');
const value = await 'b';
console.log('after await', value);
return value;
};
//Simplified version of async foo function
function foo() {
let resolve;
@gskachkov
gskachkov / async.function.promise.all.and.race.js
Last active June 3, 2017 10:20
Example of using promise all and race function with async function
//TODO: Add console.log results
async function foo () {
console.log('foo-start');
const result = await 'a';
console.log('foo-end');
return result;
}
async function boo() {