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

Support setting an optional base context for functions. #287

Merged
merged 4 commits into from May 30, 2020

Conversation

krak3n
Copy link
Contributor

@krak3n krak3n commented Apr 27, 2020

Issue #, if available:

n/a


Description of changes:

Adds support for setting a base context to be given to functions that take context as their first argument. Current implementation is to provide a context.Background(). This implements a similar feature as seen in net/http where a http.Server can be given a BaseContext function which returns a context.Context to be given to all http requests: https://golang.org/src/net/http/server.go#L2572

This avoids the need for injecting context values into the context before a function is called.

This is a non breaking API change as new explicit methods have been added to support passing in a base context.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Collaborator

@bmoffatt bmoffatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Just have some comments around the Function type.

}

// NewFunction which creates a Function with a given Handler
func NewFunction(handler Handler) *Function {
return &Function{handler: handler}
}

// NewFunctionWithContext which creates a Function with a given Handler and sets the base Context.
func NewFunctionWithContext(ctx context.Context, handler Handler) *Function {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be private? NewFunction doesn't really have a reason to be in the public API, so it'd be nice to not increase surface area further.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmoffatt removed this function. I decided to go for the http.Request.WithContext approach instead, except that WithContext is not exported on the Function. I think that's a little cleaner 👍

}

// Context returns the base context used for the fn.
func (fn *Function) Context() context.Context {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private, or moved inside of Invoke. The public visibility of the other Function methods is done only as a requirement of the net/ipc library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmoffatt made this un exported 👍

@bmoffatt bmoffatt self-assigned this May 20, 2020
@codecov-commenter
Copy link

codecov-commenter commented May 21, 2020

Codecov Report

Merging #287 into master will increase coverage by 0.08%.
The diff coverage is 52.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
+ Coverage   74.51%   74.60%   +0.08%     
==========================================
  Files          13       13              
  Lines         624      638      +14     
==========================================
+ Hits          465      476      +11     
- Misses        121      123       +2     
- Partials       38       39       +1     
Impacted Files Coverage Δ
lambda/entry.go 0.00% <0.00%> (ø)
lambda/function.go 67.74% <83.33%> (+6.95%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c67fade...0d6c14c. Read the comment docs.

@bmoffatt bmoffatt removed their assignment May 21, 2020
@bmoffatt bmoffatt merged commit 26aa364 into aws:master May 30, 2020
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 this pull request may close these issues.

None yet

3 participants