Asynchrony (original) (raw)
(This is an experimental features! To use it with node, you should install promise
package.)
With async
modificator function returns a Promise
. In async
function available resolve
and reject
operators.
async GET(String url) { var xhr = new XMLHttpRequest();
xhr.onreadystatechange() {
if (xhr.readyState != 4) return;
if (xhr.status == 200) resolve xhr.response;
reject false;
}
xhr.open("GET", url, true);
xhr.send();
}
await
operator can call async
functions (or functions which returns a Promise
)
Object info = await GET("info.json"); console.log(info);