Example #1
0
func main() {
	//	q, _ := qr.New(
	//		d,
	//		uid,
	//		//			qr.OptionBuffer(1),
	//		qr.OptionTimeout(time.Duration(1)*time.Second),
	//	)
	q, _ := qr.New(
		"/home/figo/data/sampleTtlQ/q/",
		"example",
		qr.OptionBuffer(1000),
	)
	q.Enqueue("test1")
	q.Close()
	q, _ = qr.New(
		"/home/figo/data/sampleTtlQ/q/",
		"example",
		qr.OptionBuffer(1000),
	)
	q.Enqueue("test2")
	q.Close()
	q, _ = qr.New(
		"/home/figo/data/sampleTtlQ/q/",
		"example",
		qr.OptionBuffer(1000),
	)
	q.Enqueue("test3")
	q.Close()
	q, _ = qr.New(
		"/home/figo/data/sampleTtlQ/q/",
		"example",
		qr.OptionBuffer(1000),
	)
	rt := 0
	for {
		select {
		case v := <-q.Dequeue():
			log.Println("@v:", v)
		default:
			rt = rt + 1
			if rt > 10 {
				return
			}
			log.Println("not found val")
			time.Sleep(time.Second)
		}
	}
}
Example #2
0
func main() {
	q, err := qr.New(
		"/tmp/",
		"example",
		qr.OptionBuffer(100),
		qr.OptionTest("your datatype"),
	)
	if err != nil {
		panic(err)
	}
	defer q.Close()
	//	go func() {
	//		for e := range q.Dequeue() {
	//			fmt.Printf("We got: %v\n", e)
	//		}
	//	}()

	time.Sleep(time.Duration(time.Minute * 2))
}
Example #3
0
func (p *FileTtlQ) getQ(uid interface{}) *qr.Qr {
	qn := p.parseQName(uid)
	v := p.timerCache.Get(uid)
	if v == nil {
		d := fmt.Sprintf("%s/%s/q/%s", p.basePath, p.qname, getOkDir(qn))
		err := os.MkdirAll(d, 0777)
		utee.Chk(err)
		q, err := qr.New(
			d,
			qn,
			qr.OptionBuffer(1000),
		)
		utee.Chk(err)
		p.timerCache.Put(uid, q)
		return q
	}
	q := v.(*qr.Qr)
	return q
}