MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / newFunctionJSServer

Function newFunctionJSServer

db/functions/js_runner.go:45–57  ·  view source on GitHub ↗

Creates a JSServer instance wrapping a userJSRunner, for user JS functions.

(ctx context.Context, name string, what string, sourceCode string)

Source from the content-addressed store, hash-verified

43
44// Creates a JSServer instance wrapping a userJSRunner, for user JS functions.
45func newFunctionJSServer(ctx context.Context, name string, what string, sourceCode string) (*sgbucket.JSServer, error) {
46 js := fmt.Sprintf(kJavaScriptWrapper, sourceCode)
47 jsServer := sgbucket.NewJSServer(ctx, js, 0, kUserFunctionCacheSize,
48 func(ctx context.Context, fnSource string, timeout time.Duration) (sgbucket.JSServerTask, error) {
49 return newJSRunner(ctx, name, what, fnSource)
50 })
51 // Call WithTask to force a task to be instantiated, which will detect syntax errors in the script. Otherwise the error only gets detected the first time a client calls the function.
52 var err error
53 _, err = jsServer.WithTask(ctx, func(sgbucket.JSServerTask) (any, error) {
54 return nil, nil
55 })
56 return jsServer, err
57}
58
59// An object that runs a user JavaScript function.
60// Not thread-safe! Owned by an sgbucket.JSServer, which arbitrates access to it.

Callers 1

compileFunctionFunction · 0.85

Calls 1

newJSRunnerFunction · 0.85

Tested by

no test coverage detected