Creates a JSServer instance wrapping a userJSRunner, for user JS functions.
(ctx context.Context, name string, what string, sourceCode string)
| 43 | |
| 44 | // Creates a JSServer instance wrapping a userJSRunner, for user JS functions. |
| 45 | func 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. |
no test coverage detected