Skip to content

Commit

Permalink
Merge pull request #54 from muzzammilshahid/simplify-inv-function
Browse files Browse the repository at this point in the history
Simplify invocation function
  • Loading branch information
muzzammilshahid authored Sep 20, 2024
2 parents 4cb8800 + 0814e80 commit 432893e
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@ func TestRegisterCall(t *testing.T) {
session := connect(t)
reg, err := session.Register(
"foo.bar",
func(ctx context.Context, invocation *xconn.Invocation) (*xconn.Result, *xconn.Error) {
return &xconn.Result{Arguments: []any{"hello"}}, nil
func(ctx context.Context, invocation *xconn.Invocation) *xconn.Result {
return &xconn.Result{Arguments: []any{"hello"}}
},
nil,
)
8 changes: 4 additions & 4 deletions examples/rpc/callee/main.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ const testProcedureEcho = "io.xconn.echo"
const testProcedureSum = "io.xconn.sum"

// Function to handle received Invocation for "io.xconn.sum"
func sumHandler(_ context.Context, inv *xconn.Invocation) (*xconn.Result, *xconn.Error) {
func sumHandler(_ context.Context, inv *xconn.Invocation) *xconn.Result {
log.Printf("Received invocation: args=%s, kwargs=%s, details=%s", inv.Arguments, inv.KwArguments, inv.Details)
sum := int64(0)
for _, i := range inv.Arguments {
@@ -24,7 +24,7 @@ func sumHandler(_ context.Context, inv *xconn.Invocation) (*xconn.Result, *xconn
sum = sum + arg
}
}
return &xconn.Result{Arguments: []any{sum}}, nil
return &xconn.Result{Arguments: []any{sum}}
}

func main() {
@@ -37,10 +37,10 @@ func main() {
}

// Define function to handle received Invocation for "io.xconn.echo"
echoHandler := func(_ context.Context, inv *xconn.Invocation) (*xconn.Result, *xconn.Error) {
echoHandler := func(_ context.Context, inv *xconn.Invocation) *xconn.Result {
log.Printf("Received invocation: args=%s, kwargs=%s, details=%s", inv.Arguments, inv.KwArguments, inv.Details)

return &xconn.Result{Arguments: inv.Arguments, KwArguments: inv.KwArguments, Details: inv.Details}, nil
return &xconn.Result{Arguments: inv.Arguments, KwArguments: inv.KwArguments, Details: inv.Details}
}

// Register procedure "io.xconn.echo"
9 changes: 4 additions & 5 deletions session.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import (
"github.com/xconnio/wampproto-go/serializers"
)

type InvocationHandler func(ctx context.Context, invocation *Invocation) (*Result, *Error)
type InvocationHandler func(ctx context.Context, invocation *Invocation) *Result
type EventHandler func(event *Event)

type Session struct {
@@ -134,11 +134,10 @@ func (s *Session) processIncomingMessage(msg messages.Message) error {
}

var msgToSend messages.Message
res, invErr := endpoint(context.Background(), inv)
if invErr != nil {
res := endpoint(context.Background(), inv)
if res.Err != "" {
msgToSend = messages.NewError(
int64(invocation.Type()), invocation.RequestID(), map[string]any{}, invErr.URI, invErr.Arguments,
invErr.KwArguments,
int64(invocation.Type()), invocation.RequestID(), map[string]any{}, res.Err, res.Arguments, res.KwArguments,
)
} else {
msgToSend = messages.NewYield(invocation.RequestID(), nil, res.Arguments, res.KwArguments)
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ type Result struct {
Arguments []any
KwArguments map[string]any
Details map[string]any
Err string
}

type Error struct {

0 comments on commit 432893e

Please sign in to comment.