interface{} to any
This commit is contained in:
parent
df56b0eedf
commit
e95babaa25
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -21,3 +21,6 @@
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
# Test directories
|
||||||
|
routes/
|
||||||
|
static/
|
|
@ -2,13 +2,13 @@ package workers
|
||||||
|
|
||||||
// JobResult represents the result of a Lua script execution
|
// JobResult represents the result of a Lua script execution
|
||||||
type JobResult struct {
|
type JobResult struct {
|
||||||
Value interface{} // Return value from Lua
|
Value any // Return value from Lua
|
||||||
Error error // Error if any
|
Error error // Error if any
|
||||||
}
|
}
|
||||||
|
|
||||||
// job represents a Lua script execution request
|
// job represents a Lua script execution request
|
||||||
type job struct {
|
type job struct {
|
||||||
Bytecode []byte // Compiled LuaJIT bytecode
|
Bytecode []byte // Compiled LuaJIT bytecode
|
||||||
Params map[string]interface{} // Parameters to pass to the script
|
Params map[string]any // Parameters to pass to the script
|
||||||
Result chan<- JobResult // Channel to send result back
|
Result chan<- JobResult // Channel to send result back
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ func NewPool(numWorkers int) (*Pool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitWithContext sends a job to the worker pool with context
|
// SubmitWithContext sends a job to the worker pool with context
|
||||||
func (p *Pool) SubmitWithContext(ctx context.Context, bytecode []byte, params map[string]interface{}) (interface{}, error) {
|
func (p *Pool) SubmitWithContext(ctx context.Context, bytecode []byte, params map[string]any) (any, error) {
|
||||||
if !p.isRunning.Load() {
|
if !p.isRunning.Load() {
|
||||||
return nil, ErrPoolClosed
|
return nil, ErrPoolClosed
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (w *worker) resetState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setParams sets job parameters as a global 'params' table
|
// setParams sets job parameters as a global 'params' table
|
||||||
func (w *worker) setParams(params map[string]interface{}) error {
|
func (w *worker) setParams(params map[string]any) error {
|
||||||
// Create new table for params
|
// Create new table for params
|
||||||
w.state.NewTable()
|
w.state.NewTable()
|
||||||
|
|
||||||
|
@ -157,6 +157,6 @@ func (w *worker) executeJob(j job) JobResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit sends a job to the worker pool
|
// Submit sends a job to the worker pool
|
||||||
func (p *Pool) Submit(bytecode []byte, params map[string]interface{}) (interface{}, error) {
|
func (p *Pool) Submit(bytecode []byte, params map[string]any) (any, error) {
|
||||||
return p.SubmitWithContext(context.Background(), bytecode, params)
|
return p.SubmitWithContext(context.Background(), bytecode, params)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user