-
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.
Merge pull request #2 from proxima-one/add-preprocces
refactor, add interface for easy consuming without chan interface
- Loading branch information
Showing
8 changed files
with
338 additions
and
262 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
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
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,56 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/proxima-one/streamdb-client-go/model" | ||
"sync" | ||
) | ||
|
||
type TransitionPreprocessingResult struct { | ||
wg sync.WaitGroup | ||
res any | ||
err error | ||
} | ||
|
||
type TransitionPreprocessingFunc func(t *model.Transition) (any, error) | ||
|
||
func NewTransitionPreprocessingResult(t *model.Transition, f TransitionPreprocessingFunc) *TransitionPreprocessingResult { | ||
res := &TransitionPreprocessingResult{ | ||
wg: sync.WaitGroup{}, | ||
res: nil, | ||
err: nil, | ||
} | ||
res.wg.Add(1) | ||
go func() { | ||
res.res, res.err = f(t) | ||
res.wg.Done() | ||
}() | ||
return res | ||
} | ||
|
||
func (tr *TransitionPreprocessingResult) PreprocessingResult() (any, error) { | ||
tr.wg.Wait() | ||
return tr.res, tr.err | ||
} | ||
|
||
type ProximaStreamObject struct { | ||
Transition *model.Transition | ||
Preprocess *TransitionPreprocessingResult | ||
} | ||
|
||
func JsonParsingPreprocessFunc(transition *model.Transition) (any, error) { | ||
m := make(map[string]interface{}) | ||
err := json.Unmarshal(*transition.Event.Payload, &m) | ||
return m, err | ||
} | ||
|
||
type ProximaStreamSimpleReaderInterface interface { | ||
Start(ctx context.Context) error | ||
ReadNext() (*ProximaStreamObject, error) | ||
} | ||
|
||
type ProximaStreamProviderInterface interface { | ||
StartGrpcStreamChannel(ctx context.Context) (<-chan *ProximaStreamObject, <-chan error, error) //uses grpc stream inside | ||
StartGrpcRpcChannel(ctx context.Context, countPerRequest int) (<-chan *ProximaStreamObject, <-chan error, error) //uses grpc rpc call inside | ||
} |
Oops, something went wrong.