開放性問答

Javascript 的非同步很難寫?

callback hell

Sync

it('can handle commands synchronously', function () {
    var value = browser.getValue('#input');
    console.log(value); // outputs: some value
});

Promise

it('handles commands as promises', function () {
    return browser.getValue('#input').then(function (value) {
        console.log(value); // outputs: some value
    });
});

async/await

it('can handle commands using async/await', async function () {
    var value = await browser.getValue('#input');
    console.log(value); // outputs: some value
});

results matching ""

    No results matching ""