Skip to content

async notifications need improvement #105

@fuchsnj

Description

@fuchsnj

Currently it seems like there are 2 ways to use async notifications.

1: blocking

let connection = Connection::connect(...);
let notification = connection.notifications().next_block().unwrap()

Using this method, it doesn't seem possible to do any queries on this connection while it is blocking (listen / unlisten query) so it is mostly useless except for a few use-cases.

2: polling

let connection =Connection::connect(...);
loop{//while app is running
   let result = connection.query(...);//do some query
   for notification in connection.notifications(){
      ... do something with notification
   }
}

This method only works if you are constantly sending queries on every connection listening for notifications, otherwise a connection will not receive the notification until the next query is sent (which isn't very async!) or a dummy query is sent (which kills performance!).

Method 2 (polling) would be somewhat acceptable if there was a method to retrieve async notifications without having to run a query. (It would check the input stream and process any messages from postgres, but not block if no data exists).

A best case scenario I think would be if you could register a background listener to a connection (it would probably have to be a thread running in the background until Rust has better non-blocking IO) where you give it the sender of a channel (https://doc.rust-lang.org/std/sync/mpsc/fn.channel.html) and receive a message on the channel on each notification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions