Skip to content

Commit

Permalink
Expose multiple roles by giving it a name
Browse files Browse the repository at this point in the history
Refs #1834
  • Loading branch information
thewilkybarkid committed Sep 4, 2024
1 parent c214a84 commit a1f6c1a
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,27 +133,29 @@ if (env.VERIFY_CACHE) {

class Express extends Context.Tag('Express')<Express, ReturnType<typeof app>>() {}

pipe(
Effect.acquireRelease(
Effect.gen(function* () {
const app = yield* Express
const listeningHttpServer = app.listen(3000)
L.debug('Server listening')(loggerEnv)()
return listeningHttpServer
const expressServerLifecycle = Effect.acquireRelease(
Effect.gen(function* () {
const app = yield* Express
const listeningHttpServer = app.listen(3000)
L.debug('Server listening')(loggerEnv)()
return listeningHttpServer
}),
server =>
Effect.promise(async () => {
L.debug('Shutting server down')(loggerEnv)()
server.close()

await redis
.quit()
.then(() => L.debug('Redis disconnected')(loggerEnv)())
.catch((error: unknown) =>
L.warnP('Redis unable to disconnect')({ error: E.toError(error).message })(loggerEnv)(),
)
}),
server =>
Effect.promise(async () => {
L.debug('Shutting server down')(loggerEnv)()
server.close()
)

await redis
.quit()
.then(() => L.debug('Redis disconnected')(loggerEnv)())
.catch((error: unknown) =>
L.warnP('Redis unable to disconnect')({ error: E.toError(error).message })(loggerEnv)(),
)
}),
),
pipe(
expressServerLifecycle,
Layer.scopedDiscard,
Layer.launch,
Effect.provideServiceEffect(Express, expressServer),
Expand Down

0 comments on commit a1f6c1a

Please sign in to comment.