-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |