Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Promise.allSettled in postgres eventstore adapter dispose #2184

Merged
merged 3 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ const dispose = async (pool: AdapterPool): Promise<void> => {
if (pool.connection != null) {
const log = getLog('dispose')

const extraClient = pool.extraConnections.values()
const extraClients = Array.from(pool.extraConnections.values())
pool.extraConnections.clear()

//TODO: Promise.allSettled
for (const client of extraClient) {
try {
await client.end()
} catch (error) {
log.error(`Could not end extra client connection: ${error}`)
const endResults = await Promise.allSettled(
extraClients.map((client) => client.end())
)
for (const result of endResults) {
if (result.status === 'rejected') {
log.error(`Could not end extra client connection: ${result.reason}`)
}
}

//TODO: Promise.allSettled
const loaders = pool.eventLoaders.values()
for (const loader of loaders) {
await loader.close()
const loaders = Array.from(pool.eventLoaders.values())
pool.eventLoaders.clear()

const closeResults = await Promise.allSettled(
loaders.map((loader) => loader.close())
)
for (const result of closeResults) {
if (result.status === 'rejected') {
log.error(`Could not close event loader connection: ${result.reason}`)
}
}

const connection = pool.connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const executeStatement = async (
throw new ServiceBusyError(error.message)
}
reconnectionTimes++
await new Promise((resolve) => setTimeout(resolve, SERVICE_WAIT_TIME))
await new Promise((resolve) =>
setTimeout(resolve, delayBeforeReconnection)
)
continue
} else {
throw makeConnectionError(error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2018",
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"allowJs": true,
Expand Down