Skip to content

How to I receive NOTIFY from other processes? #149

@letharion

Description

@letharion

I have this simple test program:

let conn = Connection::connect("postgres://test:test@localhost", &SslMode::None).unwrap();
conn.execute("LISTEN chan", &[]);
let notifications = conn.notifications();

conn.execute("NOTIFY chan, 'rust'", &[]);
let mut it = notifications.iter();
for i in 0..99999999 {
    let a = it.next();
    match a {
       Some(b) => {
           println!("{:?}", b);
       }
       _ => {}
    }
}

The notification that I send with 'rust' as payload gets printed, and everything looks fine. However, if I then go into psql, and send NOTIFY chan, 'psql'; while the loop is running, that notification never seems to show up.

I also did a long sleep while I sent notifications from psql, instead of long loop, but that didn't have any other effect. (Not that I really know why it would)

The other way works fine however. If I LISTEN chan; from psql, then I receive the 'rust' payload.

I'm probably doing something wrong that has an easy fix, but I can't work out what it is, any help would be appreciated. :)

$ rustc --version
rustc 1.5.0-beta.2 (b0f440163 2015-10-28)
$ psql --version
psql (PostgreSQL) 9.4.5

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