/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
vendor/github.com/jonboulle/clockwork/context.go
25 строк
790 B
svartmetal
[Disk Manager] add cloud/disk_manager target
18 дек 2023, 23:07
18 дек 2023, 23:07
5221f36
Код
Авторство
О чём код?
package clockwork import ( "context" ) // contextKey is private to this package so we can ensure uniqueness here. This // type identifies context values provided by this package. type contextKey string // keyClock provides a clock for injecting during tests. If absent, a real clock should be used. var keyClock = contextKey("clock") // clockwork.Clock // AddToContext creates a derived context that references the specified clock. func AddToContext(ctx context.Context, clock Clock) context.Context { return context.WithValue(ctx, keyClock, clock) } // FromContext extracts a clock from the context. If not present, a real clock is returned. func FromContext(ctx context.Context) Clock { if clock, ok := ctx.Value(keyClock).(Clock); ok { return clock } return NewRealClock() }