Re: How about synchronous notifications?

Поиск
Список
Период
Сортировка
От Vick Khera
Тема Re: How about synchronous notifications?
Дата
Msg-id AANLkTimCPN+UdS7tuZgsWD+N3dPHexBfH21Rz64_oUbg@mail.gmail.com
обсуждение исходный текст
Ответ на How about synchronous notifications?  (Lincoln Yeoh <lyeoh@pop.jaring.my>)
Список pgsql-general
On Tue, Sep 21, 2010 at 12:23 PM, Lincoln Yeoh <lyeoh@pop.jaring.my> wrote:
> To me what would also be useful would be synchronous notifications.
>
> This would allow many programs to wait for events to happen rather than all
> of them polling the database (and wasting CPU cycles, battery life, etc).
> You could still poll with a suitable timeout if you want.
>

Here's how you do it: first, make sure you are not within a
transaction or other Pg activity.  Get the socket's file handle from
the Pg connection handle.  When you're ready to wait for a notify
event, just do a select() system call on that file handle waiting
until there is data to read on that socket.

When you return from the select, just check for the notifications and
you're ready to go.  If you did not find a notification, return to the
select() call.  Of course, this assumes you've issued the necessary
LISTEN command.

This has worked for me (and is tested well) up thru Pg 8.3. I cannot
imagine it would stop working as the wire line protocol doesn't really
change.

В списке pgsql-general по дате отправления:

Предыдущее
От: Mike Christensen
Дата:
Сообщение: Re: What's wrong with this query?
Следующее
От: Vick Khera
Дата:
Сообщение: Re: versioned pl/pgsql functions