Skip to content

Commit

Permalink
Make it easier to read
Browse files Browse the repository at this point in the history
Refs #1834
  • Loading branch information
thewilkybarkid committed Aug 28, 2024
1 parent 01eef17 commit 3ef035e
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,29 @@ const expressServer = app({

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

NodeRuntime.runMain(
Layer.launch(
pipe(
Layer.scopedDiscard(
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()
pipe(
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)(),
)
}),
),
),
Layer.provide(Layer.sync(Express, () => expressServer)),
),
await redis
.quit()
.then(() => L.debug('Redis disconnected')(loggerEnv)())
.catch((error: unknown) =>
L.warnP('Redis unable to disconnect')({ error: E.toError(error).message })(loggerEnv)(),
)
}),
),
Layer.scopedDiscard,
Layer.provide(Layer.sync(Express, () => expressServer)),
Layer.launch,
NodeRuntime.runMain,
)

0 comments on commit 3ef035e

Please sign in to comment.