Last active
September 2, 2020 16:37
-
-
Save risentveber/b3d6bcdf61d3cabbfe29637f1623a638 to your computer and use it in GitHub Desktop.
This file contains 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 dynamicqueue | |
import ( | |
"fmt" | |
"strconv" | |
"sync" | |
"testing" | |
"time" | |
) | |
type handler struct { | |
sync.Mutex | |
names []string | |
} | |
func (h *handler) OnItem(item interface{}) { | |
time.Sleep(time.Second) | |
h.Lock() | |
defer h.Unlock() | |
fmt.Println("process", item) | |
h.names = append(h.names, item.(string)) | |
} | |
func TestNewDynamicQueue(t *testing.T) { | |
h := &handler{} | |
q := NewDynamicQueue(3, h) | |
for i := 0; i < 10; i++ { | |
q.Add(strconv.Itoa(i)) | |
fmt.Println("add", i) | |
} | |
q.Stop() | |
if len(h.names) != 10 { | |
t.Errorf("invalid count %d %s", len(h.names), h.names) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment