database

package
v0.0.0-...-7a622f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package database implements the persistence layer for the gpu debugger tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build(ctx context.Context, r Resolvable) (interface{}, error)

Build stores resolvable into d, and then resolves and returns the resolved object.

func GetOrBuild

func GetOrBuild(ctx context.Context, r Resolvable) (interface{}, error)

GetOrBuild stores resolvable into d, if the object is already resolved in the database, returns it. Otherwise it schdules the resource to be build and returns nil.

func Put

Put amends a Context by attaching a Database reference to it.

func Resolve

func Resolve(ctx context.Context, id id.ID) (interface{}, error)

Resolve resolves id with the database held by the context.

func Store

func Store(ctx context.Context, v interface{}) (id.ID, error)

Store stores v to the database held by the context.

Types

type Database

type Database interface {
	// Store adds a key-value pair to the database.
	// If the id is already mapped to an object,
	// then nothing is stored.
	Store(context.Context, interface{}) (id.ID, error)
	// Resolve attempts to resolve the final value associated with an id.
	// It will traverse all Resolvable objects, blocking until they are ready.
	Resolve(context.Context, id.ID) (interface{}, error)
	// IsResolved returns true if the object is in the database,
	// and has already been resolved, and false if either the object
	// is not in the database, or is, but has not been resolved yet.
	IsResolved(context.Context, id.ID) bool
	// Contains returns true if the database has an entry for the specified id.
	Contains(context.Context, id.ID) bool
}

Database is the interface to a resource store.

func Get

func Get(ctx context.Context) Database

Get returns the Database attached to the given context.

func NewInMemory

func NewInMemory(ctx context.Context) Database

NewInMemory builds a new in memory database.

type Resolvable

type Resolvable interface {
	// Resolve constructs and returns the lazily-built object.
	Resolve(ctx context.Context) (interface{}, error)
}

Resolvable is the interface for types that redirects database resolves to an object lazily built using Resolve(). The Resolve() method will be called the first time the object is resolved, and all subsequent resolves will return the same pre-built object. Resolvable is commonly implemented by objects that generate data that is expensive to calculate but can be deterministically produced using the information stored in the Resolvable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL