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
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;
const foo = async () => console.log('foo');
const boo = async () => {
console.log('boo');
const result = await 'b';
return result;
};
async function foo() {};
typeof foo === 'function'; //true
foo[Symbol.toStringTag] === 'AsyncFunction'; //true
@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);
@gskachkov
gskachkov / async.function.controller.js
Created June 19, 2017 07:38
Using async function in angular 1.5
const _fooService = new WeakMap();
class FooController {
constructor(fooService) {
this.name = 'fooController';
_fooService.set(this, fooService);
this.title = 'Show data';
@gskachkov
gskachkov / async.function.decorator.js
Last active May 24, 2020 22:21
Decorator for async function in angular
import decoratorHelper from 'decorator.helper';
// Current decorator allow async function to be used in angular
// without adding unnecessary digest calls
const ngAync = function () {
return function (target, key, descriptor) {
const fn = descriptor.value;
descriptor.value = function () {
const result = fn.apply(this, arguments);
import ngAsync from 'ng-async.decorator';
class FooController {
.....
@ngAsync()
async doFoo() {
this.asyncResult = await this.loadData();
this.status = 'loaded';
}
@gskachkov
gskachkov / variable.special.symbol.js
Created June 19, 2017 14:21
Special characters in variable names
var ಠ_ಠ = 15;
ಠ_ಠ = ಠ_ಠ + 10;
console.log(ಠ_ಠ);
var ge\u006Enetic = 'ABCD'
conosle.log(ge\u006Enetic);
conosle.log(gennetic);
function foo () { retur\u006E 'boo'; }
// SyntaxError: Keyword must not contain escaped character