import * as Effect from 'effect/Effect'
import { pipe } from 'effect/Function'
async function a() {
throw new Error(`this is a rejection`)
return `this is a resolve`
}
function b() { // not async
throw new Error(`this is NOT a rejection. it should be a defect.`)
return Promise.resolve(`this is a resolve`)
}
Effect.runFork(
Effect.gen(function* () {
const result1 = yield* pipe(Effect.tryPromise(a), Effect.exit)
const result2 = yield* pipe(Effect.tryPromise(b), Effect.exit) // this should be a defect
yield* Effect.log(result1)
yield* Effect.log(result2)
}),
)
import * as Effect from 'effect/Effect'
import { pipe } from 'effect/Function'
async function a() {
throw new Error(`this is a rejection`)
return `this is a resolve`
}
function b() { // not async
throw new Error(`this is NOT a rejection. it should be a defect.`)
return Promise.resolve(`this is a resolve`)
}
Effect.runFork(
Effect.gen(function* () {
const result1 = yield* pipe(Effect.tryPromise(a), Effect.exit)
const result2 = yield* pipe(Effect.tryPromise(b), Effect.exit) // this should be a defect
yield* Effect.log(result1)
yield* Effect.log(result2)
}),
)