Open jgoux opened 2 months ago
Adding note here for others after we chatted on Discord here: https://discord.com/channels/933657521581858818/1212676471588520006/1225898205292793928
Good idea on making PGlite an EventEmitter, we should do that, and it's needed for when we support pg_notify.
It's currently possible to await pg.waitReady
, this is a promise that resolves at the end of the init
. We can't wait for that inside execProtocol
as execProtocol
is itself used inside the init
and that would result in a deadlock.
I've purposely not documented execProtocol
yet as I want feedback on its design, and whats the best way for it to work for the server simulation use case.
We could have public and privet versions of execProtocol
, an internal one without waitRead
and a public one with it.
I missed waitReady
! For now, it's more than enough for my use case. 👍
Hey, it's me again. 😄
execProtocol
is not checking if the database is ready, which triggers this error when called externally to send wire protocol messages:I see 3 solutions:
await this.#checkReady();
in theexecProtocol
functionexecProtocol
as is for internal use withinPGlite
but exposing a version withawait this.#checkReady();
appliedPGlite
extendsEventEmitter
and emits aready
event when ready (my favorite solution)In the end, I think
execProtocol
is exposed for low-level implementations such aspglite-server
so I wouldn't do extra work inexecProtocol
.