github.com/ipld/go-ipld-prime@v0.21.0/linking/preload/preload.go (about)

     1  package preload
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ipld/go-ipld-prime/datamodel"
     7  )
     8  
     9  // Loader is a function that will be called with a link discovered in a preload
    10  // pass of a traversal. A preload pass can be used to collect all links in each
    11  // block prior to traversal of that block, allowing for parallel (background)
    12  // loading of blocks in anticipation of eventual actual load during traversal.
    13  type Loader func(PreloadContext, Link)
    14  
    15  // PreloadContext carries information about the current state of a traversal
    16  // where a set of links that may be preloaded were encountered.
    17  type PreloadContext struct {
    18  	// Ctx is the familiar golang Context pattern.
    19  	// Use this for cancellation, or attaching additional info
    20  	// (for example, perhaps to pass auth tokens through to the storage functions).
    21  	Ctx context.Context
    22  
    23  	// Path where the link was encountered.  May be zero.
    24  	//
    25  	// Functions in the traversal package will set this automatically.
    26  	BasePath datamodel.Path
    27  
    28  	// Parent of the LinkNode.  May be zero.
    29  	//
    30  	// Functions in the traversal package will set this automatically.
    31  	ParentNode datamodel.Node
    32  }
    33  
    34  // Link provides the link encountered during a preload pass, the node it was
    35  // encountered on, and the segment of the path that led to the link.
    36  type Link struct {
    37  	Segment  datamodel.PathSegment
    38  	LinkNode datamodel.Node
    39  	Link     datamodel.Link
    40  }