Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLLoader should take a context #200

Open
nemith opened this issue Nov 18, 2024 · 0 comments · May be fixed by #201
Open

URLLoader should take a context #200

nemith opened this issue Nov 18, 2024 · 0 comments · May be fixed by #201

Comments

@nemith
Copy link
Contributor

nemith commented Nov 18, 2024

Adding a loader can result in i/o such as network to fetch the referenced schemas. Because of this they should be cancelable via a context.

I suggest that the URLLoader take a ctx. As a result a Compiler.Compile() call should take a context as well.

This would be a breaking change and could wait until a v7 release and/or the existing release could be updated with Context aware methods.

A proposal support in v6:

func (Compiler) CompileContext(ctx context.Context, loc string) (*Schema, error)
// MustCompile omitted as it seems less useful with a context
func (Compiler) RegisterLoaderContext(loader URLLoaderContext)

type URLLoaderContext interface {
	// This could also still just be Load().  there shouldn't be a use case to support both Load and LoadContext. 
	LoadContext(ctx context.Context, url [string](https://pkg.go.dev/builtin#string)) ([any](https://pkg.go.dev/builtin#any), [error](https://pkg.go.dev/builtin#error))
}
```

Internally the `defaultLoader` would always use the context version.  `RegisterLoader()` would just then wrap a URLoader with one that adds a default context.Background() by default 
@nemith nemith linked a pull request Nov 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant