I have a controller (MyController), which requests data from a websocket connection (wsService) while initialising.
What is the best way to detect and wait that the websocket connection is open and then place the request from the controller?
Now I'm using following solution:
my_controller.dart:
MyController(wsService ws){
// when refresh() in wsService is called,
// the call is redirected to MyController's load()
ws.refresh = load;
}
load(){
ws.send(request);
}
ws_service.dart:
onConnect(){ //this is called when websocket connection is opened
refresh(); //this calls MyController's load()
}