You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I took an example_test.go and just run two goroutines one enqueueing consecutive integers, another doing blocking dequeue and just print them from time to time.
Segment size 50, then switches to 100000.
Interrupting the program, and the starting it again, causes it to read corrupted data:
2022/02/23 15:26:49 Error creating new dque unable to create queue segment in /tmp/item-queue: unable to load queue segment in /tmp/item-queue: segment file /tmp/item-queue/0000000000041.dque is corrupted: error reading gob data from file: EOF exit status 1
Source:
package main
import (
"fmt""log""github.com/joncrlsn/dque"
)
funcmain() {
ExampleDQue()
}
// Item is what we'll be storing in the queue. It can be any struct// as long as the fields you want stored are public.typeItemstruct {
NamestringIdint
}
// ItemBuilder creates a new item and returns a pointer to it.// This is used when we load a segment of the queue from disk.funcItemBuilder() interface{} {
return&Item{}
}
// ExampleDQue shows how the queue worksfuncExampleDQue() {
qName:="item-queue"qDir:="/tmp"segmentSize:=100000q, err:=dque.NewOrOpen(qName, qDir, segmentSize, ItemBuilder)
iferr!=nil {
log.Fatal("Error creating new dque ", err)
}
gofunc() {
i:=0for {
err:=q.Enqueue(&Item{"Joe", i})
iferr!=nil {
log.Fatal("Error enqueueing", err)
}
i++//log.Println("Queue size:", q.Size())
}
}()
func() {
for {
varifaceinterface{}
// Dequeue the next item in the queue and block until one is availableififace, err=q.DequeueBlock(); err!=nil {
log.Fatal("Error dequeuing item ", err)
}
// Assert type of the response to an Item pointer so we can work with ititem, ok:=iface.(*Item)
if!ok {
log.Fatal("Dequeued object is not an Item pointer")
}
doSomething(item)
}
}()
}
funcdoSomething(item*Item) {
ifitem.Id%100000==0 {
fmt.Println("Dequeued:", item)
}
}
The text was updated successfully, but these errors were encountered:
I took an example_test.go and just run two goroutines one enqueueing consecutive integers, another doing blocking dequeue and just print them from time to time.
Segment size 50, then switches to 100000.
Interrupting the program, and the starting it again, causes it to read corrupted data:
2022/02/23 15:26:49 Error creating new dque unable to create queue segment in /tmp/item-queue: unable to load queue segment in /tmp/item-queue: segment file /tmp/item-queue/0000000000041.dque is corrupted: error reading gob data from file: EOF exit status 1
Source:
The text was updated successfully, but these errors were encountered: