Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fiforce

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fiforce

Ensure FIFO ordering of asynchronous calls

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Fiforce

Force FIFO on asynchronous callbacks

Problem

Sometimes order must be guaranteed. Consider the following pseudo-JS, in which UDP packets are received, lookups are made on the packets, then the packets are passed to the next component:

socket.on('message', function (message) {
    timeConsumingLookup(message, function (result) {
        // we can get here out of order!
        passToNext(message, result);
    });
});

Assuming timeConsumingLookup can take a relatively long time, we can accumulate multiple packets in the timeConsumingLookup processing simultaneously, and may get to its callback out-of-order. In other words, we might call passToNext on a result for a packet that was received after another packet for which timeConsumingLookup is still processing.

Solution

Use Fiforce!

var fiforce = new Fiforce();

socket.on('message', function (message) {
    timeConsumingLookup(message, fiforce(function (result) {
        // we only get here in order!
        passToNext(message, result);
    }));
});

Keywords

FAQs

Package last updated on 17 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc