@@ -35,9 +35,11 @@ export interface Interface {
3535 readonly connect : (
3636 workspaceID : ID ,
3737 ) => Effect . Effect < EnvironmentDriver , NotFound | WorkspaceDriver . Error | WorkspaceDriver . ProviderNotFound >
38- readonly destroy : (
39- workspaceID : ID ,
40- ) => Effect . Effect < void , NotFound | WorkspaceDriver . Error | WorkspaceDriver . ProviderNotFound >
38+ /** Makes the workspace absent; reports whether this call destroyed an existing workspace. */
39+ readonly destroy : ( workspaceID : ID ) => Effect . Effect <
40+ Workspace . DestroyResult ,
41+ WorkspaceDriver . Error | WorkspaceDriver . ProviderNotFound
42+ >
4143}
4244
4345export interface Options {
@@ -79,13 +81,16 @@ const layer = (options: Options) =>
7981 const fork = yield * FiberSet . makeRuntime < never , void , never > ( )
8082 const idleThreshold = Duration . toMillis ( options . idleThreshold ?? Duration . minutes ( 20 ) )
8183
82- const load = Effect . fn ( "Workspace.load" ) ( function * ( workspaceID : ID ) {
83- const row = yield * db
84+ const find = ( workspaceID : ID ) =>
85+ db
8486 . select ( )
8587 . from ( WorkspaceTable )
8688 . where ( eq ( WorkspaceTable . id , workspaceID ) )
8789 . get ( )
8890 . pipe ( Effect . orDie )
91+
92+ const load = Effect . fn ( "Workspace.load" ) ( function * ( workspaceID : ID ) {
93+ const row = yield * find ( workspaceID )
8994 if ( ! row ) return yield * new NotFound ( { workspaceID } )
9095 return row
9196 } )
@@ -267,9 +272,10 @@ const layer = (options: Options) =>
267272 attempts . delete ( workspaceID )
268273 Deferred . doneUnsafe ( attempt , Exit . fail ( new NotFound ( { workspaceID } ) ) )
269274 }
270- yield * locks . withLock ( workspaceID ) (
275+ return yield * locks . withLock ( workspaceID ) (
271276 Effect . gen ( function * ( ) {
272- const row = yield * load ( workspaceID )
277+ const row = yield * find ( workspaceID )
278+ if ( ! row ) return { destroyed : false }
273279 const connection = connections . get ( workspaceID )
274280 connections . delete ( workspaceID )
275281 if ( connection ) yield * Scope . close ( connection . scope , Exit . void )
@@ -284,6 +290,7 @@ const layer = (options: Options) =>
284290 ) ,
285291 )
286292 yield * db . delete ( WorkspaceTable ) . where ( eq ( WorkspaceTable . id , workspaceID ) ) . run ( ) . pipe ( Effect . orDie )
293+ return { destroyed : true }
287294 } ) ,
288295 )
289296 } ) ,
0 commit comments