Function
To define your custom function for data processing, you must implement a Go function in the following format:
func CustomFunc(source *task.Collection,
result *task.Collection,
context *task.TaskContext) bool {
// do whatever...
return true
}
And then get it registered:
// if custom function signature is not provided,
// GoCollaborate will reflect the function name as default signature
collaborate.Set("Function", CustomFunc[, "your_custom_func_signature"])
The task dataset is sent to your custom Function while the Workers enter the execution phase.
Hash Function
A HashFunction is a special type of Function that usually bears a short-term usage of the function instance, to register a HashFunction, you can go:
hashstr := collaborate.Set("HashFunction", CustomFunc)
This is useful in some scenarios where thousands of functions are registered on the same node, or when you need to maintain a dynamic registry of function literals. The HashFunction will be automatically cleaned up on a regular basis to release more memory space when it's consumed.
The hash string could be passed on to any task you created dynamically in the runtime or simply use it as a reference to call a function from store:
import (
"github.com/GoCollaborate/src/store"
)
store.GetInstance().Call(hashstr, source *task.Collection,
result *task.Collection,
context *task.TaskContext)