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 / async.method.in.class.js
Last active June 13, 2017 14:25
async method in class
async function foo(value) {
// Return async result async
return new Promise(resolve => {
setTimeout(() => resolve(value), 100);
});
}
class SuperClass {
async getValue(value) {
var result = await foo(value);
async function foo() {};
typeof foo === 'function'; //true
foo[Symbol.toStringTag] === 'AsyncFunction'; //true
const foo = async () => console.log('foo');
const boo = async () => {
console.log('boo');
const result = await 'b';
return result;
};
let resolve;
const promise = new Promise(_resolve => {
resolve = _resolve;
});
async function foo () {
console.log('start foo');
// We return promise, but fullfil handler will not be executed until this promise will be resolved
return promise;
@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() {
@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.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.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.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 / 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() {