mirror of
https://github.com/logos-storage/logos-storage-go.git
synced 2026-01-02 13:23:11 +00:00
refactors GotManifest cancellation mechanism to match the pattern used in other places
This commit is contained in:
parent
05ab491bca
commit
37bd27abf1
2
.gitignore
vendored
2
.gitignore
vendored
@ -13,6 +13,8 @@ output.bin
|
||||
*.coverprofile
|
||||
coverage*.txt
|
||||
coverage*.out
|
||||
coverage*.html
|
||||
coverage*.cov
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
|
||||
@ -42,33 +42,28 @@ func NewCodexIndexDownloader(codexClient CodexClientInterface, indexCid string,
|
||||
func (d *CodexIndexDownloader) GotManifest() <-chan struct{} {
|
||||
ch := make(chan struct{})
|
||||
|
||||
// Create cancellable context
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
// Monitor for cancellation in separate goroutine
|
||||
go func() {
|
||||
select {
|
||||
case <-d.cancelChan:
|
||||
cancel() // Cancel fetch immediately
|
||||
case <-ctx.Done():
|
||||
// Context already cancelled, nothing to do
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer cancel() // Ensure context is cancelled when fetch completes or fails
|
||||
|
||||
// Reset datasetSize to 0 to indicate no successful fetch yet
|
||||
d.mu.Lock()
|
||||
d.datasetSize = 0
|
||||
d.downloadError = nil
|
||||
d.mu.Unlock()
|
||||
|
||||
// Check for cancellation before starting
|
||||
select {
|
||||
case <-d.cancelChan:
|
||||
return // Exit without closing channel - cancellation
|
||||
default:
|
||||
}
|
||||
|
||||
// Create cancellable context for HTTP request
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
// Monitor for cancellation in separate goroutine
|
||||
go func() {
|
||||
select {
|
||||
case <-d.cancelChan:
|
||||
cancel()
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}()
|
||||
|
||||
// Fetch manifest from Codex
|
||||
manifest, err := d.codexClient.FetchManifestWithContext(ctx, d.indexCid)
|
||||
if err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user