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
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
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
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
const _fooService = new WeakMap(); | |
class FooController { | |
constructor(fooService) { | |
this.name = 'fooController'; | |
_fooService.set(this, fooService); | |
this.title = 'Show data'; |
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
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); |
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
import ngAsync from 'ng-async.decorator'; | |
class FooController { | |
..... | |
@ngAsync() | |
async doFoo() { | |
this.asyncResult = await this.loadData(); | |
this.status = 'loaded'; | |
} |
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 ಠ_ಠ = 15; | |
ಠ_ಠ = ಠ_ಠ + 10; | |
console.log(ಠ_ಠ); |
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 ge\u006Enetic = 'ABCD' | |
conosle.log(ge\u006Enetic); | |
conosle.log(gennetic); |
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
function foo () { retur\u006E 'boo'; } | |
// SyntaxError: Keyword must not contain escaped character |