Flarum (2.x)
    Preparing search index...
    • Reads a response streamed with Flarum\Http\EventStream, handing over each event as its line arrives. app.request can't be used for one: it gives the body only once it's complete.

      It's a chunk of its own, loaded the first time it's imported:

      const { default: readEventStream } = await import('flarum/common/utils/readEventStream');
      
      await readEventStream(app.forum.attribute('apiUrl') + '/acme/import', { method: 'POST' }, (event) => {
        if (event.type === 'imported') this.count += event.count as number;
        m.redraw();
      });
      

      Resolves once the response has ended. Whether the work finished is for the events to say: a dropped connection ends a response just as finished work does.

      Parameters

      Returns Promise<void>

      EventStreamRefusedError when the server answers with an error before streaming.

      TypeError when the request can't be made, or the connection drops.