asaskevich / EventBus

[Go] Lightweight eventbus with async compatibility for Go
MIT License
1.74k stars 220 forks source link

adds SubscribeAsyncWithNewContext #37

Open szimmer1 opened 5 years ago

szimmer1 commented 5 years ago

Adds and implements an interface method SubscribeAsyncWithNewContext with same signature as SubscribeAsync but is "Context-aware" by creating a new context.Background() to pass to the handler function.

My company has this use case because our server handles incoming requests partly by Publish-ing an event to a topic with at least one async subscriber which makes other outbound network requests. The server cancels the context once it sends a response. Routinely, the cancelled context from the upstream request prevents the subscriber handler function from completing.

This feature allows subscribers to opt into being called with a background Context so that cancelled contexts do not adversely affect them.

szimmer1 commented 5 years ago

Looks like this project supports go versions well before 1.7 when the context package was added to the standard lib. Feel free to close the PR if this is a breaking change.