Skip to content

Commit d235cb2

Browse files
committed
services: make db-instance-legacy-mongo-client.ts example runnable
1 parent 900600a commit d235cb2

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

packages/services/examples/db-instance-legacy-mongo-client.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ const program = Effect.gen(function*() {
2828

2929
/*** main.ts ***/
3030

31-
const MyDbLive = DbInstance.fromMongoClient(
32-
MyDb,
33-
Effect.gen(function*() {
34-
const client = yield* Effect.promise(() => LegacyConnectionPool.mongoClient("mongodb://localhost:27017"))
35-
return { database: { name: "mydb" }, client }
36-
})
37-
)
38-
39-
await program.pipe(
40-
Effect.provide(MyDbLive),
41-
Effect.runPromise
42-
)
43-
4431
class LegacyConnectionPool {
4532
private static instance: MongoClient | null = null
4633

@@ -51,4 +38,22 @@ class LegacyConnectionPool {
5138
}
5239
return this.instance
5340
}
41+
42+
static async close() {
43+
if (!this.instance) return
44+
await this.instance.close()
45+
}
5446
}
47+
48+
const MyDbLive = DbInstance.fromMongoClient(
49+
MyDb,
50+
Effect.gen(function*() {
51+
const client = yield* Effect.promise(() => LegacyConnectionPool.mongoClient("mongodb://localhost:27017"))
52+
return { database: { name: "mydb" }, client }
53+
})
54+
)
55+
56+
await program.pipe(
57+
Effect.provide(MyDbLive),
58+
Effect.runPromise
59+
).then(() => LegacyConnectionPool.close())

0 commit comments

Comments
 (0)