Skip to content

How to put conditions in ferret? #666

Answered by ziflex
vartika102 asked this question in Q&A
Discussion options

You must be logged in to vote

I meet the same question.
In my case I just use return None,fmt.errorf(xxx) to raise an error in my embeded version to stop all the ferret script runtime.

In embedded scenario, you can pass in a context with cancellation and terminate an execution at any time.

1.I have an udf in my case:
fetch_navigate_url := func(ctx context.Context, args ...core.Value) (core.Value, error) {
do you mean by cancel the ctx here?

No, I mean when you start an execution of your script, pass the context into Program.Run method:


	c := compiler.New()
	p := c.MustCompile(`
		FOR i IN 1..1000
		   RETURN i * 2
	`)

	ctx, cancel := context.WithCancel(context.Background())

	go func() {
			<-someChan
			cance…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ziflex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
type/question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #337 on September 20, 2021 00:31.