http2-syncdeprecated

Write concurrent http2 requests in one tcp packet

Usage no npm install needed!

<script type="module">
  import http2Sync from 'https://cdn.skypack.dev/http2-sync';
</script>

README

http2-sync

Build Status

💿 Installation

npm i http2-sync

📖 Usage

import SyncClient from "http2-sync";
const SyncClient = require("http2-sync");

import http2 from "http2";

const sync = new SyncClient();
const client = http2.connect("https://example.com", {
  createConnection: sync.createConnection
});

sync.cork(5);

for (let i = 0; i < 5; ++i) {
  const stream = client.request({ ":path": "/" });
  stream.on('data' console.log)
}

🌚 SyncClient

Properties

createConnection

createConnection: Function;
  • Need to be passed to http2.connect as createConnection param
/* Usage example */
http2.connect("https://example.com", {
  createConnection: sync.createConnection
});

Methods

cork

cork(count: Number = 0)
  • count - uncork after count frames with END_STREAM flag received

Buffer requests instead of writing they to socket

/* Usage example */
sync.cork();

sync.cork(5);

uncork

uncork();

Write all saved buffer in one tcp packet

/* Usage example */
sync.uncork();

wait

wait(count: Number = 1);
  • count - wait for count frames with END_STREAM flag

Wait for frames with END_STREAM flag

/* Usage example */
await sync.wait(5);

📝 License

Released under MIT license

🦉 Alex Owl