Commit c34361dc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent f3eafccb
......@@ -29,15 +29,18 @@ import (
// Task represents currently running operation.
type Task struct {
Parent *Task
Name string
parent *Task
name string
}
func (t *Task) Parent() *Task { return t.parent }
func (t *Task) Name() string { return t.name }
type taskKey struct{}
// Running creates new task and returns new context with that task set to current.
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.
......@@ -68,7 +71,7 @@ func ErrContext(errp *error, ctx context.Context) {
if task == nil {
return
}
xerr.Context(errp, task.Name)
xerr.Context(errp, task.name)
}
// String returns string representing whole operational stack.
......@@ -82,10 +85,10 @@ func (t *Task) String() string {
return ""
}
prefix := t.Parent.String()
prefix := t.parent.String()
if 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