This file contains hidden or 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
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); |
This file contains hidden or 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
async function foo() {}; | |
typeof foo === 'function'; //true | |
foo[Symbol.toStringTag] === 'AsyncFunction'; //true |
This file contains hidden or 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 foo = async () => console.log('foo'); | |
const boo = async () => { | |
console.log('boo'); | |
const result = await 'b'; | |
return result; | |
}; |
This file contains hidden or 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
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; |
This file contains hidden or 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
//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() { |
This file contains hidden or 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
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; |
This file contains hidden or 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
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), |
This file contains hidden or 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 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'); |
This file contains hidden or 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
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(); |
This file contains hidden or 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
class SuperClass { | |
constructor() { | |
print('SuperClass constructor') | |
} | |
} | |
let ProxiedSuperClass = new Proxy(SuperClass, {}); | |
class A extends ProxiedSuperClass { | |
constructor() { |