File tree Expand file tree Collapse file tree 1 file changed +18
-13
lines changed
packages/services/examples Expand file tree Collapse file tree 1 file changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -28,19 +28,6 @@ const program = Effect.gen(function*() {
28
28
29
29
/*** main.ts ***/
30
30
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
-
44
31
class LegacyConnectionPool {
45
32
private static instance : MongoClient | null = null
46
33
@@ -51,4 +38,22 @@ class LegacyConnectionPool {
51
38
}
52
39
return this . instance
53
40
}
41
+
42
+ static async close ( ) {
43
+ if ( ! this . instance ) return
44
+ await this . instance . close ( )
45
+ }
54
46
}
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 ( ) )
You can’t perform that action at this time.
0 commit comments