Socket
Socket
Sign inDemoInstall

fiforce

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fiforce

Ensure FIFO ordering of asynchronous calls


Version published
Maintainers
1
Install size
3.14 kB
Created

Readme

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

Last updated on 18 Jul 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc