mirror of
https://github.com/Linloir/Simple-TCP-Server.git
synced 2026-02-04 13:03:34 +08:00
Avoid collision on response emission by changing the listening method on the response stream from listen() to await for()
This commit is contained in:
parent
eae2ceb3eb
commit
877d0626cb
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author : Linloir
|
* @Author : Linloir
|
||||||
* @Date : 2022-10-08 15:10:04
|
* @Date : 2022-10-08 15:10:04
|
||||||
* @LastEditTime : 2022-10-09 20:21:53
|
* @LastEditTime : 2022-10-09 21:24:07
|
||||||
* @Description :
|
* @Description :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -41,9 +41,17 @@ class TCPController {
|
|||||||
required this.socket
|
required this.socket
|
||||||
}) {
|
}) {
|
||||||
socket.listen(socketHandler);
|
socket.listen(socketHandler);
|
||||||
_outStreamController.stream.listen((response) async {
|
//This future never ends, would that be bothersome?
|
||||||
await socket.addStream(response.stream);
|
Future(() async {
|
||||||
|
await for(var response in _outStreamController.stream) {
|
||||||
|
await socket.addStream(response.stream);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
//This one will fail if two request are handled simultaneously, which cause a stream
|
||||||
|
//adding to the socket which was already added by the previous stream
|
||||||
|
// _outStreamController.stream.listen((response) async {
|
||||||
|
// await socket.addStream(response.stream);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
//Listen to the incoming stream and emits event whenever there is a intact request
|
//Listen to the incoming stream and emits event whenever there is a intact request
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user