Created
July 10, 2024 17:38
-
-
Save BK1031/f5c8f8ba398863ec66050fd392daf0ac to your computer and use it in GitHub Desktop.
racecar_analytics callback/subscription system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ecuCallbacks []func(ecu ECU) | |
var batteryCallbacks []func(battery Battery) | |
func RegisterECUCallback(callback func(ecu ECU)) { | |
ecuCallbacks = append(ecuCallbacks, callback) | |
} | |
func RegisterBatteryCallback(callback func(battery Battery)) { | |
batteryCallbacks = append(batteryCallbacks, callback) | |
} | |
func PushECU(ecu ECU) { | |
for _, callback := range ecuCallbacks { | |
callback(ecu) | |
} | |
} | |
func PushBattery(battery Battery) { | |
for _, callback := range batteryCallbacks { | |
callback(battery) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment