bind static method
Async factory to create or return the singleton instance Thread-safe: uses Completer to prevent race conditions
Implementation
static Future<ShspSocketSingleton> bind() async {
// If already initialized, return existing instance
if (_instance != null) return _instance!;
// If initialization is in progress, wait for it to complete
if (_initializationCompleter != null) {
return _initializationCompleter!.future;
}
// Start initialization
_initializationCompleter = Completer<ShspSocketSingleton>();
ShspSocketInfoSingleton info = ShspSocketInfoSingleton();
MessageCallbackMapSingleton callbacks = MessageCallbackMapSingleton();
final rawSocket = await RawDatagramSocket.bind(info.address, info.port);
_instance = ShspSocketSingleton._internal(rawSocket, callbacks);
_initializationCompleter!.complete(_instance!);
return _instance!;
}