package eventbusimport ()type subSettings struct { buffer int name string}var subCnt atomic.Int64var subSettingsDefault = subSettings{buffer: 16,}// newSubSettings returns the settings for a new subscriber// The default naming strategy is sub-<fileName>-L<lineNum>func newSubSettings() subSettings { := subSettingsDefault , , , := runtime.Caller(2) // skip=1 is eventbus.Subscriberif { = strings.TrimPrefix(, "github.com/")// remove the version number from the path, for example // go-libp2p-package@v0.x.y-some-hash-123/file.go will be shortened go go-libp2p-package/file.goif := strings.Index(, "@"); != -1 {if := strings.Index([:], "/"); != -1 { = [:] + [+:] } } .name = fmt.Sprintf("%s-L%d", , ) } else { .name = fmt.Sprintf("subscriber-%d", subCnt.Add(1)) }return}func ( int) func(interface{}) error {returnfunc( interface{}) error { .(*subSettings).buffer = returnnil }}func ( string) func(interface{}) error {returnfunc( interface{}) error { .(*subSettings).name = returnnil }}type emitterSettings struct { makeStateful bool}// Stateful is an Emitter option which makes the eventbus channel// 'remember' last event sent, and when a new subscriber joins the// bus, the remembered event is immediately sent to the subscription// channel.//// This allows to provide state tracking for dynamic systems, and/or// allows new subscribers to verify that there are Emitters on the channelfunc ( interface{}) error { .(*emitterSettings).makeStateful = truereturnnil}typeOptionfunc(*basicBus)func ( MetricsTracer) Option {returnfunc( *basicBus) { .metricsTracer = .wildcard.metricsTracer = }}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.