Javascript 角度和服务器发送的事件:关闭方法调用不会关闭数据流

Javascript 角度和服务器发送的事件:关闭方法调用不会关闭数据流,javascript,angular,spring-boot,spring-webflux,server-sent-events,Javascript,Angular,Spring Boot,Spring Webflux,Server Sent Events,技术堆栈:Angular 7,Spring webflux(带Spring boot),Chrome浏览器 由于策略限制,我无法共享实际代码。感谢你的理解 我举了一个例子: 我有一个布尔变量makeCall作为if-else的条件开关 当用户单击屏幕上的按钮时,TogglesCall方法包含以下逻辑在Angular component中调用 切换调用方法的主体: makeCall: boolean = true; toggleSseCall() { let eventSource = n

技术堆栈:Angular 7,Spring webflux(带Spring boot),Chrome浏览器

由于策略限制,我无法共享实际代码。感谢你的理解

我举了一个例子:

我有一个布尔变量makeCall作为if-else的条件开关
当用户单击屏幕上的按钮时,TogglesCall方法包含以下逻辑在Angular component中调用

切换调用方法的主体:

makeCall: boolean = true;

toggleSseCall() {
   let eventSource = new EventSource(url);
    if(makeCall) {
        Call service method: getServerSentEvents(eventSource) //similar to the example in link one difference being i'm passing the Instantiated eventSource reference
        Subscribe to the observable returned by the above call like in the example and console log the data 
    } else {  //When user clicks the button again, call goes here as makeCall is false
        //Call flow comes here as expected, I verified that with console logging
        eventSource.close(); //I verified to make sure the close method is not uppercase or anything like that
    }
    makeCall = !makeCall //toggle boolean flag
}
服务器端: 只需RESTFul Get Api调用,该调用返回Flux,Flux只需每隔x秒返回hello字符串

呼叫正在进行,“hello”文本按预期从后端流到前端。但是,数据流不会在调用close方法时停止。我希望在用户再次单击按钮时关闭数据流。如果您对此有任何建议,我们将不胜感激