import { Console, Effect as E } from 'effect'
const process = (_: object) => E.gen(function*() {
yield* Console.log("processing start")
yield* E.sleep("2 seconds")
yield* Console.log("processing end")
// would post to some other service
return "done"
})
const isValid = (msg: string) => E.gen(function*() {
yield* Console.log(`message '${msg}' is valid `)
return true
})
// mimic incomming data of http request
const body = { message: 'hi' }
// Mimic express endpoint handler
const start = E.gen(function*() {
if (yield* isValid(body.message)) {
// Q: how do I get this to run even if the calling function ends?
E.fork(process(body))
return 200
} else {
return 400
}
})
E.runPromise(start)
import { Console, Effect as E } from 'effect'
const process = (_: object) => E.gen(function*() {
yield* Console.log("processing start")
yield* E.sleep("2 seconds")
yield* Console.log("processing end")
// would post to some other service
return "done"
})
const isValid = (msg: string) => E.gen(function*() {
yield* Console.log(`message '${msg}' is valid `)
return true
})
// mimic incomming data of http request
const body = { message: 'hi' }
// Mimic express endpoint handler
const start = E.gen(function*() {
if (yield* isValid(body.message)) {
// Q: how do I get this to run even if the calling function ends?
E.fork(process(body))
return 200
} else {
return 400
}
})
E.runPromise(start)