Commit c34361dc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f3eafccb
...@@ -29,15 +29,18 @@ import ( ...@@ -29,15 +29,18 @@ import (
// Task represents currently running operation. // Task represents currently running operation.
type Task struct { type Task struct {
Parent *Task parent *Task
Name string name string
} }
func (t *Task) Parent() *Task { return t.parent }
func (t *Task) Name() string { return t.name }
type taskKey struct{} type taskKey struct{}
// Running creates new task and returns new context with that task set to current. // Running creates new task and returns new context with that task set to current.
func Running(ctx context.Context, name string) context.Context { func Running(ctx context.Context, name string) context.Context {
return context.WithValue(ctx, taskKey{}, &Task{Parent: Current(ctx), Name: name}) return context.WithValue(ctx, taskKey{}, &Task{parent: Current(ctx), name: name})
} }
// Runningf is Running cousin with formatting support. // Runningf is Running cousin with formatting support.
...@@ -68,7 +71,7 @@ func ErrContext(errp *error, ctx context.Context) { ...@@ -68,7 +71,7 @@ func ErrContext(errp *error, ctx context.Context) {
if task == nil { if task == nil {
return return
} }
xerr.Context(errp, task.Name) xerr.Context(errp, task.name)
} }
// String returns string representing whole operational stack. // String returns string representing whole operational stack.
...@@ -82,10 +85,10 @@ func (t *Task) String() string { ...@@ -82,10 +85,10 @@ func (t *Task) String() string {
return "" return ""
} }
prefix := t.Parent.String() prefix := t.parent.String()
if prefix != "" { if prefix != "" {
prefix += ": " prefix += ": "
} }
return prefix + t.Name return prefix + t.name
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment