コード例 #1
0
ファイル: cancel_test.go プロジェクト: hodduc/go-capnproto2
func (h Hanger) Hang(call testcapnp.Hanger_hang) error {
	server.Ack(call.Options)
	h.notify <- struct{}{}
	<-call.Ctx.Done()
	close(h.notify)
	return nil
}
コード例 #2
0
// Add implements a method
func (AdderServer) Add(call testcapnp.Adder_add) error {
	// Acknowledging the call allows other calls to be made (it returns the Answer
	// to the caller).
	server.Ack(call.Options)

	// Parameters are accessed with call.Params.
	a := call.Params.A()
	b := call.Params.B()

	// A result struct is allocated for you at call.Results.
	call.Results.SetResult(a + b)

	return nil
}
コード例 #3
0
func (hf *HandleFactory) NewHandle(call testcapnp.HandleFactory_newHandle) error {
	server.Ack(call.Options)
	if hf.singleton.Client == nil {
		hf.mu.Lock()
		hf.n++
		hf.mu.Unlock()
		call.Results.SetHandle(testcapnp.Handle_ServerToClient(&Handle{f: hf}))
	} else {
		hf.mu.Lock()
		hf.n = 1
		hf.mu.Unlock()
		call.Results.SetHandle(hf.singleton)
	}
	return nil
}
コード例 #4
0
func (de *DelayEchoer) Echo(call testcapnp.Echoer_echo) error {
	server.Ack(call.Options)
	<-de.delay
	return de.Echoer.Echo(call)
}