Per-request event bus
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 6.9k
- Forks
- 1.3k
- Avg merge
- 13d 21h
- Merged PRs (30d)
- 1
Description
Currently, the DHT has a useful but very DHT specific routing query events system for returning events related to current query. This works by attaching an event listener to the context higher up in the application and extracting it from the context down in libp2p.
The downsides are:
1. Specific to routing/DHT events and doesn't generalize well.
2. Only allows one subsystem to register for events.
Instead, we should consider stashing a per-request event bus in the context. This would allow multiple services to emit request-specific events on the event bus, and multiple consumers to consume these events.
```go
package eventctx
// NullEmitter consumes and drops all emitted events.
var NullEmitter = ...
// Subscribe subscribes to the given events, attaching a new event bus to the context if necessary.
func Subscribe(ctx context.Context, evtTypes interface{}, opts ...event.SubscriptionOpt) (context.Context, event.Subscription, error) { ... }
// Emitter registers a new emitter for the given events on the context's event bus. If no event bus has been registered, this function returns a NullEmitter.
func Emitter(ctx context.Context, evtTypes interface{}, opts ...event.EmitterOpt) (event.Emitter, error) { ... }
```
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing DHT routing query event handling and the context-based event flow described in the issue. Then examine the event subscription and emitter APIs before deciding how eventctx should expose a per-request bus. Done means multiple services can emit and consume request-specific events, while contexts without a bus safely use NullEmitter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100