Skip to content
This repository was archived by the owner on Sep 18, 2019. It is now read-only.

streaming partial response as the data becomes available #553

Closed
danielb2 opened this issue Oct 3, 2017 · 3 comments
Closed

streaming partial response as the data becomes available #553

danielb2 opened this issue Oct 3, 2017 · 3 comments
Labels

Comments

@danielb2
Copy link

danielb2 commented Oct 3, 2017

We desire to send initial HTML information (loading JS files etc) while loading the main data in order to speed up the load time for the end user.

const handler = function (request, reply) {

      const inStream = new Readable();
      inStream.push('ABCDEFGHIJKLM');
      reply(inStream);

      setTimeout(() => {

          inStream.push('NOPQRSTUVWXYZ');
          inStream.push(null);

      }, 50);
  };

The above does not work for sending partial content as it becomes available, however, if the stream is closed right away it does. Any idea how to accomplish sending chunks as it becomes available?

const handler = function (request, reply) {

      const inStream = new Readable();
      inStream.push('ABCDEFGHIJKLM');
      inStream.push(null);
      reply(inStream);

  };

the above does work.

Can this be done?

@danielb2 danielb2 changed the title partial response as it comes streaming partial response as the data becomes available Oct 3, 2017
@kanongil
Copy link

kanongil commented Oct 3, 2017

Yes. You are not creating a valid readable.

@danielb2
Copy link
Author

danielb2 commented Oct 3, 2017

@kanongil can you supply with how I should be doing it ?

@danielb2
Copy link
Author

My coworker took the discussion here

https://stackoverflow.com/questions/46634526/stream-an-html-response-using-hapi

and looks like we've made some progress

hapijs/hapi#3599

FYI @kanongil

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants