代码之家  ›  专栏  ›  技术社区  ›  Milos

延迟信号流响应

  •  0
  • Milos  · 技术社区  · 4 年前

    我使用Angular和signalR库从.NET核心后端传输数据。

    1. 长轮询

    我注意到在进行长轮询时,只有在前端不忙的情况下,前端才向后端发送请求,但我不知道如何说前端忙,而postopone请求。

    这是我在前端的集线器连接和流式处理方法:

     this.hubConnection = new HubConnectionBuilder()
          .withUrl(this.href + '/api/hub/stremingMethod', HttpTransportType.LongPolling)
          .withAutomaticReconnect()
          .build();
    
    private startStreaming(streamingId: number): signalR.ISubscription<DataModel> {
        return this.hubConnection.stream<DataModel>('StremingMethod', streamingId).subscribe({
          next: streamingData=> {
            this.addToQueue(streamingData);
          },
          complete: () => {
            console.log('complete');
          },
          error: error => {
            console.log('complete');
    
          }
        });
      }
    

    我能在信号机里有那种控制吗。目前我正在使用长轮询,我也可以使用websocket。

    0 回复  |  直到 4 年前