Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

feat: make the CoreAPI expose a streaming pin interface#38

Closed
Stebalien wants to merge 1 commit intomasterfrom
feat/streaming-pin
Closed

feat: make the CoreAPI expose a streaming pin interface#38
Stebalien wants to merge 1 commit intomasterfrom
feat/streaming-pin

Conversation

@Stebalien
Copy link
Member

No description provided.

@MichaelMure
Copy link
Contributor

Turns out I'm hitting this one because I need the pin/ls command to only rely on the CoreAPI instead of the IpfsNode, which means finishing the internal refactoring there, started by @magik6k if I'm not mistaken.

I'm hesitating between several options:

Ls(context.Context, ...options.PinLsOption) (<-chan Pin, error)

The one you suggested in this PR.
Pro: it's simple
Cons: no way to return errors after the streaming started

Ls(context.Context, ...options.PinLsOption) (<-chan Pin, <-chan error)

Pro: errors while streaming can be returned. A bit clunky to use but less that the third solution
Cons: errors before the streaming need to be sent in the error channel which make it a bit weird to implement

This API can be used like this:

var result []iface.Pin

pins, errC := api.Pin().Ls(ctx)
for pin := range pins {
	result = append(result, pin)
}

if err := <-errC; err != nil {
	return nil, err
}

Third option:

Ls(context.Context, ...options.PinLsOption) (<-chan Pin, <-chan error, error)

Pro: errors while streaming can be returned. Simpler to implement.
Cons: Clunky to use.

Any preference ?

@MichaelMure
Copy link
Contributor

Maybe better:

// Pin holds information about pinned resource
type Pin interface {
	// Path to the pinned object
	Path() path.Resolved

	// Type of the pin
	Type() string

	// if not nil, an error happened.
	Err() error
}

Ls(context.Context, ...options.PinLsOption) (<-chan Pin, error)

I'm going for this solution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants