Skip to content

Commit

Permalink
Attempt to fix unhandled promise rejection (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
andywer authored Jul 8, 2019
1 parent 4211959 commit ba944f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export interface Options {
* Timeout in ms after which to stop retrying and just fail. Defaults to 3000 ms.
*/
retryTimeout?: number;
/**
* Custom function to control how the payload data is stringified on `.notify()`.
* Use together with the `serialize` option. Defaults to `JSON.parse`.
*/
parse?: (serialized: string) => any;
/**
* Custom function to control how the payload data is stringified on `.notify()`.
* Use together with the `parse` option. Defaults to `JSON.stringify`.
*/
serialize?: (data: any) => string;
}
export interface Subscriber {
/** Emits events: "error", "notification" & "redirect" */
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ function connect (connectionConfig: pg.ClientConfig | undefined, options: Option
newClient.once("end", () => reject(Error("Connection ended.")))
newClient.once("error", reject)
})
await newClient.connect()
await connecting
await Promise.all([
newClient.connect(),
connecting
])
connectionLogger("PostgreSQL reconnection succeeded")
return newClient
} catch (error) {
Expand Down

0 comments on commit ba944f3

Please sign in to comment.