add onStart callbacks

This commit is contained in:
c9s 2021-03-15 18:04:03 +08:00
parent 4061f2aef0
commit e311a182fa
3 changed files with 16 additions and 0 deletions

View File

@ -489,6 +489,8 @@ func (environ *Environment) Connect(ctx context.Context) error {
if err := session.Stream.Connect(ctx); err != nil {
return err
}
session.Stream.EmitStart()
}
return nil

View File

@ -4,6 +4,16 @@ package types
import ()
func (stream *StandardStream) OnStart(cb func()) {
stream.startCallbacks = append(stream.startCallbacks, cb)
}
func (stream *StandardStream) EmitStart() {
for _, cb := range stream.startCallbacks {
cb()
}
}
func (stream *StandardStream) OnConnect(cb func()) {
stream.connectCallbacks = append(stream.connectCallbacks, cb)
}
@ -105,6 +115,8 @@ func (stream *StandardStream) EmitBookSnapshot(book OrderBook) {
}
type StandardStreamEventHub interface {
OnStart(cb func())
OnConnect(cb func())
OnDisconnect(cb func())

View File

@ -23,6 +23,8 @@ var KLineChannel = Channel("kline")
type StandardStream struct {
Subscriptions []Subscription
startCallbacks []func()
connectCallbacks []func()
disconnectCallbacks []func()