Running something before every effect?
Hi, is it possible to run an effect before anything? May be injected via runtime?
This is without:
The idea is something like:
This is without:
const myEffect1 = () => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someData1(user.id)
return Option.fromNullable(data)
})
const myEffect2 = (tenantId: TenantId) => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someTenantData(tenantId)
return Option.fromNullable(data)
})
const myEffect2 = () => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someData()
return Option.fromNullable(data)
})
// Then...
const result = ManageRuntime.runPromise(myEffect1())const myEffect1 = () => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someData1(user.id)
return Option.fromNullable(data)
})
const myEffect2 = (tenantId: TenantId) => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someTenantData(tenantId)
return Option.fromNullable(data)
})
const myEffect2 = () => Effect.gen(function* () {
yield* secureRequest(); // Block bots, rate limit, etc.
const data = yield* someData()
return Option.fromNullable(data)
})
// Then...
const result = ManageRuntime.runPromise(myEffect1())The idea is something like:
const myEffect1 = () => Effect.gen(function* () {
const data = yield* someData1(user.id)
return Option.fromNullable(data)
})
const myEffect2 = (tenantId: TenantId) => Effect.gen(function* () {
const data = yield* someTenantData(tenantId)
return Option.fromNullable(data)
})
const myEffect2 = () => Effect.gen(function* () {
const data = yield* someData()
return Option.fromNullable(data)
})
// Custom runtime
const myRuntime = ManagedRuntime.make(Effect.beforeAll(function* () { // May be?
yield* secureRequest(); // Block bots, rate limit, etc.
}))
// Then...
const result = myRuntime.runPromise(myEffect1())const myEffect1 = () => Effect.gen(function* () {
const data = yield* someData1(user.id)
return Option.fromNullable(data)
})
const myEffect2 = (tenantId: TenantId) => Effect.gen(function* () {
const data = yield* someTenantData(tenantId)
return Option.fromNullable(data)
})
const myEffect2 = () => Effect.gen(function* () {
const data = yield* someData()
return Option.fromNullable(data)
})
// Custom runtime
const myRuntime = ManagedRuntime.make(Effect.beforeAll(function* () { // May be?
yield* secureRequest(); // Block bots, rate limit, etc.
}))
// Then...
const result = myRuntime.runPromise(myEffect1())