Async processing #667
Answered
by
advancedlogic
advancedlogic
asked this question in
Q&A
-
Is there a way to process collected data during the harvesting time (process as you get) instead of waiting for the end of the script? Maybe using goroutines and channels? |
Beta Was this translation helpful? Give feedback.
Answered by
advancedlogic
Jun 19, 2019
Replies: 2 comments
-
Hi @advancedlogic, No, there is no such functionality, but you can register a custom function which would do it for you. compiler. RegisterFunction('consume', func(ctx context.Context, args ...core.Value) (core.Value, error) {
go func () {
// do what you need to do
// also, you can pass a control flow component with the context, that could help to orchestrate the async execution
} ()
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Here the code if you want to implement the command: ch := make(chan []byte)
defer close(ch)
comp := compiler.New()
comp.RegisterFunction("consume", func(ctx context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
return values.None, nil
}
j, _ := values.ToArray(ctx, args[0]).MarshalJSON()
ch <- j
return values.None, nil
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ziflex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here the code if you want to implement the command: