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*() {
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- 
4431class  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 ( ) ) 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments