import { DatabaseConnection } from './database-connection.js' ; import { ConnectionProvider } from './connection-provider.js' ; export class SingleConnectionProvider implements ConnectionProvider { readonly #connection : DatabaseConnection ; #runningPromise ? : Promise < void > ; constructor ( connection ) { this . #connection = connection ; } async withConnection < T > ( runner ) { while ( this . #runningPromise ) { await this . #runningPromise ; } const promise = this . #run ( runner ) ; this . #runningPromise = promise . then ( ( ) => { this . #runningPromise = undefined ; } ) . catch ( ( ) => { this . #runningPromise = undefined ; } ) ; return promise ; } async #run < T > ( runner ) { return await runner ( this . #connection ) ; } }