mirror of
https://github.com/mudler/LocalAI.git
synced 2026-04-01 21:53:01 -04:00
* feat: add distributed mode (experimental) Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix data races, mutexes, transactions Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix events and tool stream in agent chat Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * use ginkgo Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(cron): compute correctly time boundaries avoiding re-triggering Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not flood of healthy checks Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * do not list obvious backends as text backends Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * tests fixups Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactoring and consolidation Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Drop redundant healthcheck Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * enhancements, refactorings Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
35 lines
821 B
Go
35 lines
821 B
Go
package messaging
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
)
|
|
|
|
// CancelRegistry tracks cancellation functions keyed by an ID (e.g. job or agent).
|
|
// It is safe for concurrent use.
|
|
type CancelRegistry struct {
|
|
m sync.Map
|
|
}
|
|
|
|
// Register stores a cancel function for the given key.
|
|
func (r *CancelRegistry) Register(key string, cancel context.CancelFunc) {
|
|
r.m.Store(key, cancel)
|
|
}
|
|
|
|
// Cancel invokes and removes the cancel function for the given key.
|
|
// Returns true if the key was found and cancelled.
|
|
func (r *CancelRegistry) Cancel(key string) bool {
|
|
if fn, ok := r.m.LoadAndDelete(key); ok {
|
|
if cancelFn, ok := fn.(context.CancelFunc); ok {
|
|
cancelFn()
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Deregister removes the cancel function without invoking it.
|
|
func (r *CancelRegistry) Deregister(key string) {
|
|
r.m.Delete(key)
|
|
}
|