Files
tasks/chasm/context.go
Alex ShtinandGitHub 8e8f1b0f7c Remove license header from every file (#7689)
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.

## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
2025-05-01 18:50:21 -07:00

91 lines
2.0 KiB
Go

package chasm
import (
"context"
"time"
)
type Context interface {
// Context is not bound to any component,
// so all methods needs to take in component as a parameter
// NOTE: component created in the current transaction won't have a ref
// this is a Ref to the component state at the start of the transition
Ref(Component) (ComponentRef, bool)
Now(Component) time.Time
// Intent() OperationIntent
// ComponentOptions(Component) []ComponentOption
getContext() context.Context
}
type MutableContext interface {
Context
AddTask(Component, TaskAttributes, any) error
// Add more methods here for other storage commands/primitives.
// e.g. HistoryEvent
// Get a Ref for the component
// This ref to the component state at the end of the transition
// Same as Ref(Component) method in Context,
// this only works for components that already exists at the start of the transition
//
// If we provide this method, then the method on the engine doesn't need to
// return a Ref
// NewRef(Component) (ComponentRef, bool)
}
type ContextImpl struct {
ctx context.Context
// Not embedding the Node here to avoid exposing AddTask() method on Node,
// so that ContextImpl won't implement MutableContext interface.
root *Node
}
type MutableContextImpl struct {
*ContextImpl
}
func NewContext(
ctx context.Context,
root *Node,
) *ContextImpl {
return &ContextImpl{
ctx: ctx,
root: root,
}
}
func (c *ContextImpl) Ref(component Component) (ComponentRef, bool) {
return c.root.Ref(component)
}
func (c *ContextImpl) Now(component Component) time.Time {
return c.root.Now(component)
}
func (c *ContextImpl) getContext() context.Context {
return c.ctx
}
func NewMutableContext(
ctx context.Context,
root *Node,
) *MutableContextImpl {
return &MutableContextImpl{
ContextImpl: NewContext(ctx, root),
}
}
func (c *MutableContextImpl) AddTask(
component Component,
attributes TaskAttributes,
payload any,
) error {
return c.root.AddTask(component, attributes, payload)
}