Files
tasks/common/rpc/context.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

49 lines
1.5 KiB
Go

package rpc
import (
"context"
"time"
"github.com/hanzoai/tasks/common/headers"
)
type (
valueCopyCtx struct {
context.Context
valueCtx context.Context
}
)
func (c *valueCopyCtx) Value(key any) any {
if value := c.Context.Value(key); value != nil {
return value
}
return c.valueCtx.Value(key)
}
// CopyContextValues copies values in source Context to destination Context.
func CopyContextValues(dst context.Context, src context.Context) context.Context {
return &valueCopyCtx{
Context: dst,
valueCtx: src,
}
}
// ResetContextTimeout creates new context with specified timeout and copies values from source Context.
func ResetContextTimeout(ctx context.Context, newTimeout time.Duration) (context.Context, context.CancelFunc) {
newContext, cancel := context.WithTimeout(context.Background(), newTimeout)
return CopyContextValues(newContext, ctx), cancel
}
// NewContextWithTimeoutAndVersionHeaders creates context with timeout and version headers.
func NewContextWithTimeoutAndVersionHeaders(timeout time.Duration) (context.Context, context.CancelFunc) {
return context.WithTimeout(headers.SetVersions(context.Background()), timeout)
}
// NewContextFromParentWithTimeoutAndVersionHeaders creates context from parent context with timeout and version headers.
func NewContextFromParentWithTimeoutAndVersionHeaders(parentCtx context.Context, timeout time.Duration) (context.Context, context.CancelFunc) {
return context.WithTimeout(headers.SetVersions(parentCtx), timeout)
}