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
var foo = async function*() {};
typeof foo;
// "function"
foo.toString();
// "async function* () {}"
foo[Symbol.toStringTag];
// "AsyncFunction"
Promise.resolve(1)
.then(value => { console.log('fulfill:', value); return 'new value'; })
.finally(value => { console.log('finally:', value); });
// fulfill: 1
// finally: new value
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';
}
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());
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());
};
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 {
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;
}
const importObject = {
imports: {
foo: arg => {
console.log('Imported value from WASM', arg);
}
}
};
@gskachkov
gskachkov / example.js
Last active September 8, 2017 18:58
Eval function
var assertNotThrow = function (cb) {
var noError = false;
try {
cb();
noError = true;
} catch (e) {}
return noError;
}
function f() {
var foo;
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++) {