示例#1
0
func TestGo(t *testing.T) {
	l1 := NewSandbox()
	New(l1)

	l2 := NewSandbox()
	r2 := New(l2)

	types.RegisterFunc(testFunc{})

	x := &TestData{
		X: 3,
		M: make(map[string]interface{}),
		I: (*int)(nil),
	}

	for i := 0; i < 10; i++ {
		x.M["a"] = i
		reply := r2.Go(l1.Addr(), testFunc{}, "hello", x)
		if len(reply) != 1 {
			t.Fatalf("missing reply")
		}
		s, ok := reply[0].(*string)
		if !ok {
			t.Fatalf("reply type")
		}
		if *s != "hello world "+strconv.Itoa(i) {
			t.Fatalf("reply value")
		}
	}
}
示例#2
0
// RegisterFunc registers the worker function type fn with the circuit runtime type system.
// fn must be of a not-necessarily public type having a single public method.
// As a result, this program is able to spawn fn on remote hosts, as well as to host
// remote invokations of fn.
// By convention, RegisterFunc should be invoked from a dedicated init
// function within of the package that defines the type of fn.
func RegisterFunc(fn Func) {
	types.RegisterFunc(fn)
}