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 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());
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';
}
Promise.resolve(1)
.then(value => { console.log('fulfill:', value); return 'new value'; })
.finally(value => { console.log('finally:', value); });
// fulfill: 1
// finally: new value
var foo = async function*() {};
typeof foo;
// "function"
foo.toString();
// "async function* () {}"
foo[Symbol.toStringTag];
// "AsyncFunction"
var foo = async function() {};
typeof foo;
// "function"
foo.toString();
// "async function () {}"
foo[Symbol.toStringTag];
// "AsyncFunction"
async function* asyncRandomNumbers() {
// This is a web service that returns a random number
const url = 'https://www.random.org/decimal-fractions/?num=1&dec=10&col=1&format=plain&rnd=new';
while (true) {
const response = await fetch(url);
const text = await response.text();
yield Number(text);
}
}
var apiRoot = "https://jsonplaceholder.typicode.com/";
var currentUserCode = "[email protected]";
function fetchCurrentUser(cb) {
$.ajax({url: apiRoot + "users",
complete: function(result) {
if (result.status === 200) {
var users = result.responseJSON;
var currentUser = users
.filter(user => user.email === currentUserCode)
function foo () {
try {
throw new Error('Error');
} catch (boo) {
eval('{ function boo() {} }');
print(boo); // should be Error
}
print(boo); // should be function boo
}
async function getOrder1(id) {
return _http.get('some/path'+1);
}
async function getOrder2(id) {
return _http.get('some/path'+1);
}
async function flow(id) {
const someValue = await getOrder1(id);
async function foo (value) {
return Promise.resolve(value + 1);
}
async function bar (value) {
return Promise.resolve(value + 2);
}
async function foobar() {
const value = await foo(1);