Skip to content
Open
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
20 changes: 16 additions & 4 deletions cf/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
, result = new Result()
, incoming = Buffer.alloc(0)
, needsTypes = options.fetch_types
, typesPromise = null
, backendParameters = {}
, statements = {}
, statementId = Math.random().toString(36).slice(2)
Expand Down Expand Up @@ -541,12 +542,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

if (needsTypes) {
initial.reserve && (initial = null)
return fetchArrayTypes()

// Prevent duplicate requests
needsTypes = false

// Store the promise so concurrent requests can wait for type initialization to complete
typesPromise = fetchArrayTypes().finally(() => {
typesPromise = null
})
return
}

initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
// If there is a pending types request, trigger the execution after it's complete
(typesPromise || Promise.resolve()).then(() => {
initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
})
return
}

Expand Down
20 changes: 16 additions & 4 deletions cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
, result = new Result()
, incoming = Buffer.alloc(0)
, needsTypes = options.fetch_types
, typesPromise = null
, backendParameters = {}
, statements = {}
, statementId = Math.random().toString(36).slice(2)
Expand Down Expand Up @@ -539,12 +540,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

if (needsTypes) {
initial.reserve && (initial = null)
return fetchArrayTypes()

// Prevent duplicate requests
needsTypes = false

// Store the promise so concurrent requests can wait for type initialization to complete
typesPromise = fetchArrayTypes().finally(() => {
typesPromise = null
})
return
}

initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
// If there is a pending types request, trigger the execution after it's complete
(typesPromise || Promise.resolve()).then(() => {
initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
})
return
}

Expand Down
20 changes: 16 additions & 4 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
, result = new Result()
, incoming = Buffer.alloc(0)
, needsTypes = options.fetch_types
, typesPromise = null
, backendParameters = {}
, statements = {}
, statementId = Math.random().toString(36).slice(2)
Expand Down Expand Up @@ -542,12 +543,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

if (needsTypes) {
initial.reserve && (initial = null)
return fetchArrayTypes()

// Prevent duplicate requests
needsTypes = false

// Store the promise so concurrent requests can wait for type initialization to complete
typesPromise = fetchArrayTypes().finally(() => {
typesPromise = null
})
return
}

initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
// If there is a pending types request, trigger the execution after it's complete
(typesPromise || Promise.resolve()).then(() => {
initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
})
return
}

Expand Down
20 changes: 16 additions & 4 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
, result = new Result()
, incoming = Buffer.alloc(0)
, needsTypes = options.fetch_types
, typesPromise = null
, backendParameters = {}
, statements = {}
, statementId = Math.random().toString(36).slice(2)
Expand Down Expand Up @@ -539,12 +540,23 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

if (needsTypes) {
initial.reserve && (initial = null)
return fetchArrayTypes()

// Prevent duplicate requests
needsTypes = false

// Store the promise so concurrent requests can wait for type initialization to complete
typesPromise = fetchArrayTypes().finally(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this promise rejects, it throws a global promise rejection. Is there anyway to pipe through an onError handler for new connections or will this PR fix that issue as well and i am misreading the code?

Again thank you for this fix, its very much needed by our team

typesPromise = null
})
return
}

initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
// If there is a pending types request, trigger the execution after it's complete
(typesPromise || Promise.resolve()).then(() => {
initial && !initial.reserve && execute(initial)
options.shared.retries = retries = 0
initial = null
})
return
}

Expand Down