@contember/database 1.3.0-alpha.1 → 1.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/builders/Compiler.d.ts.map +1 -1
- package/dist/src/builders/Compiler.js +7 -15
- package/dist/src/builders/Compiler.js.map +1 -1
- package/dist/src/builders/InsertBuilder.d.ts +2 -2
- package/dist/src/builders/InsertBuilder.d.ts.map +1 -1
- package/dist/src/builders/InsertBuilder.js +7 -4
- package/dist/src/builders/InsertBuilder.js.map +1 -1
- package/dist/src/builders/LockType.d.ts +8 -4
- package/dist/src/builders/LockType.d.ts.map +1 -1
- package/dist/src/builders/LockType.js +10 -5
- package/dist/src/builders/LockType.js.map +1 -1
- package/dist/src/builders/SelectBuilder.d.ts +6 -3
- package/dist/src/builders/SelectBuilder.d.ts.map +1 -1
- package/dist/src/builders/SelectBuilder.js +2 -2
- package/dist/src/builders/SelectBuilder.js.map +1 -1
- package/dist/src/builders/UpdateBuilder.d.ts +3 -1
- package/dist/src/builders/UpdateBuilder.d.ts.map +1 -1
- package/dist/src/builders/UpdateBuilder.js.map +1 -1
- package/dist/src/builders/internal/Where.js +1 -1
- package/dist/src/builders/internal/Where.js.map +1 -1
- package/dist/src/client/AcquiredConnection.d.ts +4 -2
- package/dist/src/client/AcquiredConnection.d.ts.map +1 -1
- package/dist/src/client/AcquiredConnection.js +4 -0
- package/dist/src/client/AcquiredConnection.js.map +1 -1
- package/dist/src/client/Client.d.ts +1 -1
- package/dist/src/client/Client.d.ts.map +1 -1
- package/dist/src/client/Client.js.map +1 -1
- package/dist/src/client/Connection.d.ts +9 -5
- package/dist/src/client/Connection.d.ts.map +1 -1
- package/dist/src/client/Connection.js.map +1 -1
- package/dist/src/client/PgClient.d.ts +6 -4
- package/dist/src/client/PgClient.d.ts.map +1 -1
- package/dist/src/client/Pool.d.ts +1 -0
- package/dist/src/client/Pool.d.ts.map +1 -1
- package/dist/src/client/Pool.js +14 -3
- package/dist/src/client/Pool.js.map +1 -1
- package/dist/src/client/Transaction.d.ts +8 -2
- package/dist/src/client/Transaction.d.ts.map +1 -1
- package/dist/src/client/Transaction.js +2 -0
- package/dist/src/client/Transaction.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/types.d.ts +2 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +1 -0
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/listen.d.ts +32 -0
- package/dist/src/utils/listen.d.ts.map +1 -0
- package/dist/src/utils/listen.js +126 -0
- package/dist/src/utils/listen.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/builders/Compiler.ts +12 -16
- package/src/builders/InsertBuilder.ts +8 -5
- package/src/builders/LockType.ts +9 -4
- package/src/builders/SelectBuilder.ts +4 -4
- package/src/builders/UpdateBuilder.ts +1 -1
- package/src/builders/internal/Where.ts +1 -1
- package/src/client/AcquiredConnection.ts +8 -2
- package/src/client/Client.ts +3 -3
- package/src/client/Connection.ts +9 -5
- package/src/client/PgClient.ts +8 -3
- package/src/client/Pool.ts +18 -5
- package/src/client/Transaction.ts +9 -3
- package/src/index.ts +2 -0
- package/src/tsconfig.json +1 -3
- package/src/types.ts +2 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/listen.ts +140 -0
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
UniqueViolationError,
|
|
14
14
|
} from './errors'
|
|
15
15
|
import { PgClient } from './PgClient'
|
|
16
|
+
import { Notification } from 'pg'
|
|
16
17
|
|
|
17
|
-
export class AcquiredConnection implements Connection.
|
|
18
|
+
export class AcquiredConnection implements Connection.AcquiredConnectionLike {
|
|
18
19
|
private mutex = new Mutex()
|
|
19
20
|
|
|
20
21
|
constructor(
|
|
@@ -24,7 +25,7 @@ export class AcquiredConnection implements Connection.ConnectionLike {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
async scope<Result>(
|
|
27
|
-
callback: (connection: Connection.
|
|
28
|
+
callback: (connection: Connection.AcquiredConnectionLike) => Promise<Result> | Result,
|
|
28
29
|
options: { eventManager?: EventManager } = {},
|
|
29
30
|
): Promise<Result> {
|
|
30
31
|
return await this.mutex.execute(async () => {
|
|
@@ -96,6 +97,11 @@ export class AcquiredConnection implements Connection.ConnectionLike {
|
|
|
96
97
|
}
|
|
97
98
|
})
|
|
98
99
|
}
|
|
100
|
+
|
|
101
|
+
on(event: 'end' | 'notification' | 'error', cb: (() => void) | ((notification: Notification) => void) | ((error: any) => void)) {
|
|
102
|
+
this.pgClient.on(event as any, cb)
|
|
103
|
+
return () => this.pgClient.off(event as any, cb)
|
|
104
|
+
}
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
function prepareSql(sql: string) {
|
package/src/client/Client.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { DatabaseQueryable } from '../queryable'
|
|
|
3
3
|
import { Connection } from './Connection'
|
|
4
4
|
import { EventManager } from './EventManager'
|
|
5
5
|
import { QueryHandler } from '@contember/queryable'
|
|
6
|
-
import { withDatabaseAdvisoryLock } from '../utils'
|
|
6
|
+
import { withDatabaseAdvisoryLock, wrapIdentifier } from '../utils'
|
|
7
7
|
|
|
8
8
|
class Client<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> implements Connection.Queryable {
|
|
9
9
|
constructor(
|
|
@@ -19,11 +19,11 @@ class Client<ConnectionType extends Connection.ConnectionLike = Connection.Conne
|
|
|
19
19
|
return new Client<ConnectionType>(this.connection, schema, this.queryMeta, eventManager)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
async scope<T>(callback: (wrapper: Client<Connection.
|
|
22
|
+
async scope<T>(callback: (wrapper: Client<ConnectionType & Connection.AcquiredConnectionLike>) => Promise<T> | T): Promise<T> {
|
|
23
23
|
return await this.connection.scope(
|
|
24
24
|
connection => callback(
|
|
25
25
|
new Client(
|
|
26
|
-
connection,
|
|
26
|
+
connection as ConnectionType & Connection.AcquiredConnectionLike,
|
|
27
27
|
this.schema,
|
|
28
28
|
this.queryMeta,
|
|
29
29
|
new EventManager(connection.eventManager),
|
package/src/client/Connection.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Pool, PoolConfig, PoolStatus } from './Pool'
|
|
|
4
4
|
import { createPgClientFactory } from '../utils'
|
|
5
5
|
import { DatabaseConfig } from '../types'
|
|
6
6
|
import { AcquiredConnection } from './AcquiredConnection'
|
|
7
|
+
import { Notification } from 'pg'
|
|
7
8
|
|
|
8
9
|
class Connection implements Connection.ConnectionLike, Connection.ClientFactory, Connection.PoolStatusProvider {
|
|
9
10
|
constructor(
|
|
@@ -31,7 +32,7 @@ class Connection implements Connection.ConnectionLike, Connection.ClientFactory,
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
async scope<Result>(
|
|
34
|
-
callback: (connection: Connection.
|
|
35
|
+
callback: (connection: Connection.AcquiredConnectionLike) => Promise<Result> | Result,
|
|
35
36
|
options: { eventManager?: EventManager } = {},
|
|
36
37
|
): Promise<Result> {
|
|
37
38
|
const acquired = await this.pool.acquire()
|
|
@@ -103,14 +104,17 @@ namespace Connection {
|
|
|
103
104
|
& Connection.ClientFactory
|
|
104
105
|
& Connection.PoolStatusProvider
|
|
105
106
|
|
|
106
|
-
export interface
|
|
107
|
+
export interface ConnectionLike<T = {}> extends Transactional, Queryable {
|
|
107
108
|
scope<Result>(
|
|
108
|
-
callback: (connection:
|
|
109
|
+
callback: (connection: T & AcquiredConnectionLike) => Promise<Result> | Result,
|
|
109
110
|
options?: { eventManager?: EventManager },
|
|
110
111
|
): Promise<Result>
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
export interface
|
|
114
|
+
export interface AcquiredConnectionLike<T = {}> extends ConnectionLike<T> {
|
|
115
|
+
on(event: 'notification', listener: (message: Notification) => void): () => void
|
|
116
|
+
on(event: 'end', listener: () => void): () => void
|
|
117
|
+
on(event: 'error', listener: (error: any) => void): () => void
|
|
114
118
|
}
|
|
115
119
|
|
|
116
120
|
export interface ClientFactory {
|
|
@@ -121,7 +125,7 @@ namespace Connection {
|
|
|
121
125
|
getPoolStatus(): PoolStatus | undefined
|
|
122
126
|
}
|
|
123
127
|
|
|
124
|
-
export interface TransactionLike extends
|
|
128
|
+
export interface TransactionLike extends AcquiredConnectionLike<TransactionLike> {
|
|
125
129
|
readonly isClosed: boolean
|
|
126
130
|
|
|
127
131
|
rollback(): Promise<void>
|
package/src/client/PgClient.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { QueryConfig, QueryResult, QueryResultRow } from 'pg'
|
|
2
|
-
import EventEmitter from 'node:events'
|
|
1
|
+
import { Notification, QueryConfig, QueryResult, QueryResultRow } from 'pg'
|
|
3
2
|
|
|
4
|
-
export interface PgClient
|
|
3
|
+
export interface PgClient {
|
|
5
4
|
connect(): Promise<void>
|
|
6
5
|
|
|
7
6
|
query<R extends QueryResultRow = any, I extends any[] = any[]>(
|
|
@@ -10,4 +9,10 @@ export interface PgClient extends EventEmitter {
|
|
|
10
9
|
): Promise<QueryResult<R>>
|
|
11
10
|
|
|
12
11
|
end(): Promise<void>
|
|
12
|
+
|
|
13
|
+
on(event: 'notification', listener: (message: Notification) => void): this
|
|
14
|
+
on(event: 'error', listener: (err: Error) => void): this
|
|
15
|
+
on(event: 'end', listener: () => void): this
|
|
16
|
+
|
|
17
|
+
off(eventName: string | symbol, listener: (...args: any[]) => void): this
|
|
13
18
|
}
|
package/src/client/Pool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ImplementationException } from '../exceptions'
|
|
2
2
|
import { ClientErrorCodes } from './errorCodes'
|
|
3
|
-
import EventEmitter from 'node:events'
|
|
3
|
+
import { EventEmitter } from 'node:events'
|
|
4
4
|
import { ClientError, DatabaseError } from './errors'
|
|
5
5
|
import { PgClientFactory } from '../utils'
|
|
6
6
|
import { PgClient } from './PgClient'
|
|
@@ -306,6 +306,12 @@ class Pool {
|
|
|
306
306
|
client.on('error', e => {
|
|
307
307
|
this.log('Client error on idle connection has occurred: ' + e.message)
|
|
308
308
|
this.poolConfig.logError(new ClientError(e, 'runtime error'))
|
|
309
|
+
this.poolStats.connection_error_count++
|
|
310
|
+
|
|
311
|
+
if (!this.active.has(poolConnection)) {
|
|
312
|
+
this.removeIdleConnection(poolConnection)
|
|
313
|
+
this.disposeConnection(poolConnection)
|
|
314
|
+
}
|
|
309
315
|
})
|
|
310
316
|
try {
|
|
311
317
|
this.connectingCount++
|
|
@@ -410,7 +416,6 @@ class Pool {
|
|
|
410
416
|
})
|
|
411
417
|
}
|
|
412
418
|
|
|
413
|
-
|
|
414
419
|
private handleAvailableConnection(poolConnection: PoolConnection) {
|
|
415
420
|
const item = this.queue.shift()
|
|
416
421
|
const isNew = poolConnection.uses === 0
|
|
@@ -437,9 +442,7 @@ class Pool {
|
|
|
437
442
|
})
|
|
438
443
|
} else {
|
|
439
444
|
poolConnection.timerId = setTimeout(async () => {
|
|
440
|
-
|
|
441
|
-
if (index > -1) {
|
|
442
|
-
this.idle.splice(index, 1)
|
|
445
|
+
if (this.removeIdleConnection(poolConnection)) {
|
|
443
446
|
await this.disposeConnection(poolConnection)
|
|
444
447
|
this.poolStats.connection_disposed_idle_timeout_count++
|
|
445
448
|
this.log('Idle connection disposed after timeout.')
|
|
@@ -450,6 +453,16 @@ class Pool {
|
|
|
450
453
|
}
|
|
451
454
|
}
|
|
452
455
|
|
|
456
|
+
|
|
457
|
+
private removeIdleConnection(poolConnection: PoolConnection) {
|
|
458
|
+
const index = this.idle.indexOf(poolConnection)
|
|
459
|
+
if (index > -1) {
|
|
460
|
+
this.idle.splice(index, 1)
|
|
461
|
+
return true
|
|
462
|
+
}
|
|
463
|
+
return false
|
|
464
|
+
}
|
|
465
|
+
|
|
453
466
|
private async disposeConnection(connection: PoolConnection) {
|
|
454
467
|
try {
|
|
455
468
|
if (connection.disposed) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection } from './Connection'
|
|
2
2
|
import { EventManager } from './EventManager'
|
|
3
3
|
import { wrapIdentifier } from '../utils'
|
|
4
|
+
import { Notification } from 'pg'
|
|
4
5
|
|
|
5
6
|
export class Transaction implements Connection.TransactionLike {
|
|
6
7
|
public get isClosed(): boolean {
|
|
@@ -8,7 +9,7 @@ export class Transaction implements Connection.TransactionLike {
|
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
constructor(
|
|
11
|
-
private readonly connection: Connection.
|
|
12
|
+
private readonly connection: Connection.AcquiredConnectionLike,
|
|
12
13
|
private readonly savepointManager = new SavepointState(),
|
|
13
14
|
private readonly state = new TransactionLikeState(),
|
|
14
15
|
) {
|
|
@@ -61,6 +62,9 @@ export class Transaction implements Connection.TransactionLike {
|
|
|
61
62
|
await this.query(command)
|
|
62
63
|
this.state.close()
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
on = this.connection.on.bind(this.connection)
|
|
67
|
+
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
class SavePoint implements Connection.TransactionLike {
|
|
@@ -68,7 +72,7 @@ class SavePoint implements Connection.TransactionLike {
|
|
|
68
72
|
constructor(
|
|
69
73
|
public readonly savepointName: string,
|
|
70
74
|
public readonly savepointManager: SavepointState,
|
|
71
|
-
private readonly connection: Connection.
|
|
75
|
+
private readonly connection: Connection.AcquiredConnectionLike,
|
|
72
76
|
private readonly state = new TransactionLikeState(),
|
|
73
77
|
) {
|
|
74
78
|
}
|
|
@@ -125,6 +129,8 @@ class SavePoint implements Connection.TransactionLike {
|
|
|
125
129
|
await this.query(sql)
|
|
126
130
|
this.state.close()
|
|
127
131
|
}
|
|
132
|
+
|
|
133
|
+
on = this.connection.on.bind(this.connection)
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
class TransactionLikeState {
|
|
@@ -143,7 +149,7 @@ class SavepointState {
|
|
|
143
149
|
public counter = 1
|
|
144
150
|
|
|
145
151
|
public async execute<Result>(
|
|
146
|
-
connection: Connection.
|
|
152
|
+
connection: Connection.AcquiredConnectionLike,
|
|
147
153
|
callback: (connection: Connection.TransactionLike) => Promise<Result> | Result,
|
|
148
154
|
) {
|
|
149
155
|
const savepointName = `savepoint_${this.counter++}`
|
package/src/index.ts
CHANGED
package/src/tsconfig.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type JSONPrimitive = string | number | boolean | null | undefined
|
|
2
2
|
export type JSONValue = JSONPrimitive | JSONObject | JSONArray
|
|
3
|
-
export type JSONObject = { [
|
|
4
|
-
export type JSONArray = JSONValue[]
|
|
3
|
+
export type JSONObject = { readonly [K in string]?: JSONValue }
|
|
4
|
+
export type JSONArray = readonly JSONValue[]
|
|
5
5
|
|
|
6
6
|
export type Value =
|
|
7
7
|
| JSONValue
|
package/src/utils/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './assertNever'
|
|
|
2
2
|
export * from './asyncIterableTransaction'
|
|
3
3
|
export * from './ConstraintHelper'
|
|
4
4
|
export * from './createDatabaseIfNotExists'
|
|
5
|
+
export * from './listen'
|
|
5
6
|
export * from './Mutex'
|
|
6
7
|
export * from './sql'
|
|
7
8
|
export * from './retryTransaction'
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Client, Connection } from '../client'
|
|
2
|
+
import { wrapIdentifier } from './sql'
|
|
3
|
+
import { clearInterval } from 'node:timers'
|
|
4
|
+
|
|
5
|
+
type ListenArgs<P> = {
|
|
6
|
+
client: Client<Connection.AcquiredConnectionLike>
|
|
7
|
+
channel: string
|
|
8
|
+
abortSignal?: AbortSignal
|
|
9
|
+
healthCheckMs?: number
|
|
10
|
+
onMessage: (payload: P) => void
|
|
11
|
+
onError: (err: any) => void
|
|
12
|
+
onClose?: () => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export class Listener<P> {
|
|
17
|
+
constructor(
|
|
18
|
+
private readonly client: Client<Connection.AcquiredConnectionLike>,
|
|
19
|
+
private readonly channel: string,
|
|
20
|
+
private readonly onMessage: (message: P) => void,
|
|
21
|
+
private readonly options: { healthCheckMs?: number } = {},
|
|
22
|
+
) {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async run({ onClose, onError }: {
|
|
26
|
+
onError: (e: any) => void
|
|
27
|
+
onClose?: () => void
|
|
28
|
+
},
|
|
29
|
+
): Promise<{ end: () => Promise<void> }> {
|
|
30
|
+
let aborted = false
|
|
31
|
+
let onAbortInner = async () => {}
|
|
32
|
+
const onAbort = async () => {
|
|
33
|
+
aborted = true
|
|
34
|
+
await onAbortInner()
|
|
35
|
+
}
|
|
36
|
+
let cleanups: (() => void)[] = []
|
|
37
|
+
const cleanup = () => {
|
|
38
|
+
let localCleanup = cleanups
|
|
39
|
+
cleanups = []
|
|
40
|
+
localCleanup.forEach(it => it())
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
cleanups.push(this.client.connection.on('notification', ({ channel, payload }) => {
|
|
44
|
+
if (channel !== this.channel || aborted) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
this.onMessage(payload as P)
|
|
48
|
+
}))
|
|
49
|
+
await this.client.query(`LISTEN ${wrapIdentifier(this.channel)}`)
|
|
50
|
+
|
|
51
|
+
;(async () => {
|
|
52
|
+
const stopListening = async () => {
|
|
53
|
+
try {
|
|
54
|
+
await this.client.query(`UNLISTEN ${wrapIdentifier(this.channel)}`)
|
|
55
|
+
} catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
if (aborted) {
|
|
61
|
+
await stopListening()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
await new Promise<void>((resolve, reject) => {
|
|
65
|
+
onAbortInner = async () => {
|
|
66
|
+
await stopListening()
|
|
67
|
+
resolve()
|
|
68
|
+
}
|
|
69
|
+
cleanups.push(this.client.connection.on('end', reject))
|
|
70
|
+
cleanups.push(this.client.connection.on('error', reject))
|
|
71
|
+
|
|
72
|
+
const healthCheckHandle = setInterval(async () => {
|
|
73
|
+
try {
|
|
74
|
+
await this.client.query('SELECT 1')
|
|
75
|
+
} catch (e) {
|
|
76
|
+
reject(e)
|
|
77
|
+
}
|
|
78
|
+
}, this.options.healthCheckMs ?? 30_000)
|
|
79
|
+
cleanups.push(() => clearInterval(healthCheckHandle))
|
|
80
|
+
})
|
|
81
|
+
onClose?.()
|
|
82
|
+
} catch (e) {
|
|
83
|
+
onError(e)
|
|
84
|
+
} finally {
|
|
85
|
+
cleanup()
|
|
86
|
+
}
|
|
87
|
+
})()
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
end: async () => {
|
|
91
|
+
await onAbort()
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
} catch (e) {
|
|
95
|
+
cleanup()
|
|
96
|
+
throw e
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export class AcquiringListener<P> {
|
|
103
|
+
constructor(
|
|
104
|
+
private readonly client: Client,
|
|
105
|
+
private readonly channel: string,
|
|
106
|
+
private readonly onMessage: (message: P) => void,
|
|
107
|
+
private readonly options: { healthCheckMs?: number } = {},
|
|
108
|
+
) {
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async run({ onClose, onError }: { onError: (e: any) => void;onClose?: () => void },
|
|
112
|
+
): Promise<{ end: () => Promise<void> }> {
|
|
113
|
+
return new Promise(async (resolveRunning, rejectRunning) => {
|
|
114
|
+
try {
|
|
115
|
+
await this.client.scope(async db => {
|
|
116
|
+
const listener = new Listener<P>(db, this.channel, this.onMessage, this.options)
|
|
117
|
+
await new Promise<void>(async (resolveScope, rejectScope) => {
|
|
118
|
+
try {
|
|
119
|
+
const running = await listener.run({
|
|
120
|
+
onClose: resolveScope,
|
|
121
|
+
onError: rejectScope,
|
|
122
|
+
})
|
|
123
|
+
resolveRunning({
|
|
124
|
+
end: async () => {
|
|
125
|
+
await running.end()
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
} catch (e) {
|
|
129
|
+
rejectScope(e)
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
onClose?.()
|
|
134
|
+
} catch (e) {
|
|
135
|
+
rejectRunning(e)
|
|
136
|
+
onError(e)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|