This file contains 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 getFullName(username, password) { | |
let token | |
try { | |
token = await logIn(username, password); | |
} catch (error) { | |
console.error('wrong username or password') | |
return | |
} | |
const user = await getUser(token) | |
return user.fullName |
This file contains 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 getFullName = async(function* (username, password) { | |
let token | |
try { | |
token = yield logIn(username, password); | |
} catch (error) { | |
console.error('wrong username or password') | |
return | |
} | |
const user = yield getUser(token) | |
return user.fullName |
This file contains 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
FROM alpine:latest | |
COPY boost.patch /tmp | |
COPY prepare.sh /tmp | |
WORKDIR /tmp | |
RUN ./prepare.sh |
This file contains 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* g() { | |
try { | |
yield 1 // throws 'first error' | |
} catch (error) { // catches 'first error' | |
console.error('inside generator', error) | |
} | |
yield 2 // throws but does not catch 'second error' | |
return 3 // never reached because exception thrown | |
} |
This file contains 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 generator = g() | |
generator.next() // { value: 1, done: false } | |
generator.next() // { value: 2, done: false } | |
generator.next() // { value: 3, done: false } | |
generator.next(10) // { value: 11, done: true } |
This file contains 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* g() { | |
yield 1 | |
yield 2 | |
return (yield 3) + 1 | |
} |
This file contains 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
step1() | |
.then(result1 => step2(result1)) | |
.then(result2 => step3(result2)) | |
.then(result3 => step4(result3)) | |
.then(result4 => console.log(result4)) | |
.catch(error => throw error) |
This file contains 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* () { | |
const result1 = yield step1() | |
const result2 = yield step2(result1) | |
const result3 = yield step3(result2) | |
const result4 = yield step4(result3) | |
console.log(result4) | |
// Errors are implicitly thrown. | |
})() |
This file contains 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
step1(function (error, result1) { | |
if (error) throw error | |
step2(result1, function (error, result2) { | |
if (error) throw error | |
step3(result2, function (error, result3) { | |
if (error) throw error | |
step4(result3, function (error, result4) { | |
if (error) throw error | |
console.log(result4) | |
}) |
This file contains 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 () { | |
const result1 = await step1() | |
const result2 = await step2(result1) | |
const result3 = await step3(result2) | |
const result4 = await step4(result3) | |
console.log(result4) | |
}() |