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*() {}; | |
typeof foo; | |
// "function" | |
foo.toString(); | |
// "async function* () {}" | |
foo[Symbol.toStringTag]; | |
// "AsyncFunction" |
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
Promise.resolve(1) | |
.then(value => { console.log('fulfill:', value); return 'new value'; }) | |
.finally(value => { console.log('finally:', value); }); | |
// fulfill: 1 | |
// finally: new 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
const getValue = () => { console.log('get-value'); return 'value'; }; | |
async function* foo(value = getValue()) { | |
console.log('before yield', value); | |
yield value + '-yiled'; | |
console.log('after yield'); | |
return value + '-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
var all = items => Promise.all(items); | |
async function asyncRandomNumbers() { | |
const response = await fetch('https://www.random.org/decimal-fractions/?num=1&dec=10&col=1&format=plain&rnd=new'); | |
return Number(await response.text()); | |
} | |
async function getUsers(count) { | |
const response = await fetch("https://randomuser.me/api/?results=10", { method: "GET" }); | |
return JSON.parse(await response.text()); |
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 asyncRandomNumbers() { | |
const response = await fetch('https://www.random.org/decimal-fractions/?num=1&dec=10&col=1&format=plain&rnd=new'); | |
return Number(await response.text()); | |
} | |
async function getUsers(count) { | |
const response = await fetch("https://randomuser.me/api/?results=10", { method: "GET" }); | |
return JSON.parse(await response.text()); | |
}; |
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 asyncThrow = async () => { throw new Error('Rejected-value') }; | |
var reject = async () => Promise.reject('Rejected-value'); | |
var foo = async () => { | |
try { | |
await asyncThrow(); | |
} catch (e) { | |
console.log('Catched error:', e); | |
} | |
try { |
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 getResponseSize(url) { | |
const response = await fetch(url); | |
const reader = response.body.getReader(); | |
let total = 0; | |
while (true) { | |
const {done, value} = await reader.read(); | |
if (done) return total; | |
total += value.length; | |
} |
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 importObject = { | |
imports: { | |
foo: arg => { | |
console.log('Imported value from WASM', arg); | |
} | |
} | |
}; |
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 assertNotThrow = function (cb) { | |
var noError = false; | |
try { | |
cb(); | |
noError = true; | |
} catch (e) {} | |
return noError; | |
} | |
function f() { | |
var 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
async function asyncFoo(i) { | |
return Promise.resolve(i); | |
} | |
async function main() { | |
console.log(`Start`); | |
const start = Date.now() | |
let total = 0 | |
for (let i = 0;i < 550000; i++) { |