Skip to content

Instantly share code, notes, and snippets.

@bmizerany
Created July 1, 2011 00:19
Show Gist options
  • Save bmizerany/1057611 to your computer and use it in GitHub Desktop.
Save bmizerany/1057611 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/jbarham/pgsql.go"
"time"
"fmt"
)
func mustAcquire(pool *pgsql.Pool) *pgsql.Conn {
cn, err := pool.Acquire()
if err != nil {
panic(err)
}
return cn
}
func main() {
pool, err := pgsql.NewPool("dbname=testdb", 3, pgsql.DEFAULT_IDLE_TIMEOUT)
if err != nil {
panic(err)
}
cn := mustAcquire(pool)
defer pool.Release(cn)
fmt.Printf("%#v\n", cn)
go func() {
cn := mustAcquire(pool)
defer pool.Release(cn)
for _ = range time.Tick(1e9) {
fmt.Println("tick")
if err := cn.Exec("NOTIFY tick"); err != nil {
panic(err)
}
}
}()
for {
fmt.Println("consume input")
cn.ConsumeInput()
n := cn.Notifies()
if n != nil {
fmt.Printf("%v\n", n)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment