You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
576 B
Go
32 lines
576 B
Go
package observer
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestObserver(t *testing.T) {
|
|
sendEmail := make(Observer)
|
|
notifyWelcome := make(Observer)
|
|
|
|
userRegister := NewSubject()
|
|
userRegister.Attach(sendEmail, notifyWelcome)
|
|
|
|
go func() {
|
|
for data := range sendEmail {
|
|
fmt.Println("The send email service receive data: ", data)
|
|
}
|
|
}()
|
|
|
|
go func() {
|
|
for data := range notifyWelcome {
|
|
fmt.Println("The notify welcome service receive data: ", data)
|
|
}
|
|
}()
|
|
|
|
newUser1 := "fantasticbin"
|
|
newUser2 := "gan"
|
|
userRegister.Notify(newUser1)
|
|
userRegister.Notify(newUser2)
|
|
}
|