Skip to content

Instantly share code, notes, and snippets.

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
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
FROM alpine:latest
COPY boost.patch /tmp
COPY prepare.sh /tmp
WORKDIR /tmp
RUN ./prepare.sh
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
}
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 }
function* g() {
yield 1
yield 2
return (yield 3) + 1
}
step1()
.then(result1 => step2(result1))
.then(result2 => step3(result2))
.then(result3 => step4(result3))
.then(result4 => console.log(result4))
.catch(error => throw error)
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.
})()
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)
})
async function () {
const result1 = await step1()
const result2 = await step2(result1)
const result3 = await step3(result2)
const result4 = await step4(result3)
console.log(result4)
}()