Created
July 1, 2011 00:19
-
-
Save bmizerany/1057611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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