-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add api.Plugin as a base type for guest plugins #54
Add api.Plugin as a base type for guest plugins #54
Conversation
guest/internal/plugin/plugin.go
Outdated
if current == nil { | ||
current = plugin | ||
} else if current != plugin { | ||
panic("only one plugin instance is supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is important because even though we we handle state outside user code, they may define state and accidentally assign multiple instances, splitting it. Anyway it performs better per benchmarks.
sorry I will fix the tinygo test. |
yeah can't test panics with tinygo+wasm yet. I'll change accordingly tinygo-org/tinygo#2914 |
This adds `api.Plugin` as a base type for guest plugins. This is similar to `framework.Plugin`, but doesn't yet define `Name()` as there's no purpose for it. Notes on that are added to RATIONALE.md. This mostly gets the guest SDK looking much more like the framework one. This also makes it easier to test for misconfiguration, such as registering multiple instances of plugins. Signed-off-by: Adrian Cole <adrian@tetrate.io>
e10da67
to
d39d13c
Compare
tests pass re-running benchmark as I had to change the tinygo impl a bit |
bench is still a lot better. PTAL! |
// MustSet sets the plugin once | ||
func MustSet(plugin api.Plugin) { | ||
if !set(plugin) { | ||
panic("only one plugin instance is supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Whoops, I submited the review in a middle. Wait a min for the full review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: codefromthecrypt, sanposhiho The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
/kind documentation
What this PR does / why we need it:
This adds
api.Plugin
as a base type for guest plugins. This is similar toframework.Plugin
, but doesn't yet defineName()
as there's no purpose for it. Notes on that are added to RATIONALE.md.This mostly gets the guest SDK looking much more like the framework one. This also makes it easier to test for misconfiguration, such as registering multiple instances of plugins.
Which issue(s) this PR fixes:
NONE
Special notes for your reviewer:
Does this PR introduce a user-facing change?
NONE because it isn't user-ready yet!
What are the benchmark results of this change?