javascript - What's the synax `async/await` in zombiejs code? -
when read source code of zombie.js, found async/await
keyword:
before(async function() { await browser.visit('/streaming'); await browser.pressbutton('1'); });
why can use such keywords? behaviour of code? tried find clue codebase, not lucky
if check out gulpfile
used build project, can see source piped through babel
.
gulp.task('build', ['clean'], function() { return gulp .src('src/**/*.js') .pipe(sourcemaps.init()) .pipe(babel({ experimental: true, loose: 'all', optional: [ 'bluebirdcoroutines', 'runtime' ] })) });
babel transpiler allows write es6+ code , transpile es5.
babel turn es6+ code es5 friendly code, can start using right without waiting browser support.
if check out docs on babel's site, can see in es7 section of experimental section, there implementation asyncfunctions
.
these keywords part of es7 specification, haven't stabilised. hence them being included experimental features of babel.
in simplified terms, async
function allow await
call returns promise
.
async function() { // flow suspended here until // promise returned somefunction resolved await somefunction() }
es6 include known generators, similar thing, aren't specific promises. might start seeing yield
keyword around, or functions declared function* () {}
. what's known generator functions.
there particularly good article pouchdb explains real world use case these features.
Comments
Post a Comment