Files
dolt/types/future.go
T
Erik Arvidsson 8565f175ee Make sure Chunks includes type.Refs and the TypeRef
Chunks shold return the futures for types.Ref values.

For typed values that have a TypeRef which has a package ref, also
include that.
2015-10-13 11:00:51 -04:00

60 lines
1.4 KiB
Go

package types
import (
"github.com/attic-labs/noms/chunks"
"github.com/attic-labs/noms/d"
"github.com/attic-labs/noms/ref"
)
// Future encapsulates a Value which may or may not be available yet.
type Future interface {
// Returns the Ref of the value without fetching it.
Ref() ref.Ref
// Returns the Value if we already have it, nil otherwise.
Val() Value
// Fetch the Future value if necessary, then return it. Multiple calls to deref only result in one fetch.
Deref(cs chunks.ChunkSource) Value
// BUG 141. The lazy loading api is clearly not working.
Release()
}
func futuresEqual(f1, f2 Future) bool {
// If we already have both values, then use their Equals() methods since for primitives it is faster than computing a reference.
if f1.Val() != nil && f2.Val() != nil {
return f1.Val().Equals(f2.Val())
} else {
return f1.Ref() == f2.Ref()
}
}
func futureEqualsValue(f Future, v Value) bool {
d.Chk.NotNil(v)
if f.Val() != nil {
return f.Val().Equals(v)
} else {
return f.Ref() == v.Ref()
}
}
func futureFromValue(v Value) Future {
return resolvedFuture{v}
}
func appendChunks(chunks []Future, f Future) []Future {
if uf, ok := f.(*unresolvedFuture); ok {
chunks = append(chunks, uf)
} else if f != nil {
v := f.Val()
if v != nil {
if r, ok := v.(Ref); ok {
chunks = append(chunks, futureFromRef(r.Ref()))
}
}
}
return chunks
}