1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| package eventbus
import ( "fmt" "testing" "time" )
func sub1(msg1, msg2 string) { time.Sleep(1 * time.Microsecond) fmt.Printf("sub1, %s %s\n", msg1, msg2) }
func sub2(msg1, msg2 string) { fmt.Printf("sub2, %s %s\n", msg1, msg2) } func TestAsyncEventBus_Publish(t *testing.T) { bus := NewAsyncEventBus() bus.Subscribe("topic:1", sub1) bus.Subscribe("topic:1", sub2) bus.Publish("topic:1", "test1", "test2") bus.Publish("topic:1", "testA", "testB") time.Sleep(1 * time.Second) }
|