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)
|
||
|
}
|