Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the *Expr returned from Compile thread-safe? #16

Open
premchelliah opened this issue Aug 31, 2022 · 3 comments
Open

Is the *Expr returned from Compile thread-safe? #16

premchelliah opened this issue Aug 31, 2022 · 3 comments

Comments

@premchelliah
Copy link

Hi,

First, thanks for the library. I want to cache the compiled expression and use it concurrently across threads. Is this possible?

See this feature in the .Net version. https://github.com/mikhail-barg/jsonata.net.native

Thanks

@tbal999
Copy link

tbal999 commented Sep 8, 2022

i've checked for you and no it is not

passing a mutex or semaphore wrapper around it will enable you to use it concurrently although slower

@tbal999
Copy link

tbal999 commented Nov 24, 2022

package racechecker

import (
	"testing"
	"github.com/blues/jsonata-go"
)

func TestRace(t *testing.T) {
	jsnt := replaceQuotesAndCommentsInPaths("$$")

	e := jsonata.MustCompile(jsnt)

	for i := 0; i < 500; i++ {
		go func() {
			e = jsonata.MustCompile("$$")
			_, _ = e.Eval("{}")
		}()
	}
}

@premchelliah
Copy link
Author

thanks Tom for the information, appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants