http-moment

http(s).Agent that allows you to send multiple requests at exactly one moment

Usage no npm install needed!

<script type="module">
  import httpMoment from 'https://cdn.skypack.dev/http-moment';
</script>

README

http-moment

type travis npm dependencies

Multiple requests are processed by the server at exactly one specific moment

💿 Installation

npm i http-moment

❓ How it works

  1. Send buffer except the last byte to the server

  2. Ensure that all buffers are sent

  3. Simultaneously send the last bytes of all requests

📖 Usage

import { http, https } from "http-moment";
const { http, https } = require("http-moment");

const agent = new https.Agent();

agent.cork(5);

for (let i = 0; i < 5; ++i)
  request("https://example.com", { agent }, console.log);

agent.cork(2);
request("https://example.com", { agent }, console.log);
request.post("https://example.com/hello", { agent, body: "hi" }, console.log);

⏲ Http(s)Agent

Methods

cork

cork(count: Number = 0): Promise
  • count - if >= 1, would uncork agent after count requests
/* Usage example */
agent.cork();
agent.cork(0);

agent.cork(5); /* auto uncork after 5 requests */

uncork

uncork(): Promise

It's better to provide specific count instead of manual use this method

/* Usage example  */
agent.cork();
request("https://example.com", { agent }, console.log);
request("https://example.com/hello", { agent }, console.log);

// agent.uncork() - you can't use uncork immediately

setTimeout(() => agent.uncork(), 3000);

📝 License

Released under MIT license

🦉 Alex Owl