| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| // +build fuchsia |
| |
| package dispatch |
| |
| import ( |
| "syscall/zx/internal/context" |
| ) |
| |
| type dispatcherKey struct{} |
| |
| // GetDispatcher returns the dispatcher stored on ctx if it exists; otherwise |
| // the bool return value will be false. |
| func GetDispatcher(ctx context.Context) (*Dispatcher, bool) { |
| key, ok := ctx.Value(dispatcherKey{}).(*Dispatcher) |
| return key, ok |
| } |
| |
| // WithDispatcher returns a Context that embeds parent and stores dispatcher. |
| func WithDispatcher(parent context.Context, dispatcher *Dispatcher) context.Context { |
| return context.WithValue(parent, dispatcherKey{}, dispatcher) |
| } |