Skip to content

Commit

Permalink
Add ella's compiler adaptor
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed Jun 20, 2024
1 parent 4f70da6 commit c1ed74f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions adaptor/ella.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package adaptor

import (
"context"
"encoding/json"

"ella.to/bus"
)

//
// Ella is an adaptor for the compatibility of the bus.Stream and ella compiler for rpc calls
//

type Ella struct {
stream bus.Stream
}

// var _ rpcAdaptor = (*Ella)(nil)

func (b *Ella) Request(ctx context.Context, topic string, in any) (json.RawMessage, error) {
fn := bus.Request(b.stream, topic)
return fn(ctx, in)
}

func (b *Ella) Reply(ctx context.Context, topic string, fn func(ctx context.Context, data json.RawMessage) (out any, err error)) error {
bus.Reply(ctx, b.stream, topic, fn)
return nil
}

func NewElla(stream bus.Stream) *Ella {
return &Ella{stream: stream}
}

0 comments on commit c1ed74f

Please sign in to comment.