Socket
Socket
Sign inDemoInstall

fantail

Package Overview
Dependencies
1
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fantail

Simple schedule-managed queue


Version published
Weekly downloads
135
increased by70.89%
Maintainers
1
Install size
891 kB
Created
Weekly downloads
 

Readme

Source

♫ ♭♩ Fantail

Build Status NPM version Dependency Status

var Fantail = require('fantail');

Instantiation

var sch = new Fantail;

Options

Options are set at instantiation and can't be modified afterwards.

var sch = new Fantail({
  debug: false,     // Expose queues and handlers.
  throttle: 200,    // Run handlers (at most once) every 200 milliseconds
  immediate: false  // .start() immediately.
});

.push(arg: any [, arg2: any [, …]])

You can push to the queue whenever you wish.

sch.push(foo);

You can push multiple values at the same time.

sch.push(bar, baz);

.addHandler(name: string, func: function)

Handlers process items. They are named.

sch.addHandler('something', function(item) {
  // do something
});

.addPicker(iter: function, time: int, limit: int)

Pickers filter the queue. They are run every time milliseconds, and can be limited to limit items per run (limit is optional); the default is to go through everything. They are passed the item and nothing else, and have access to two methods on the this object:

  • this.stop() stops the current picker run after the present iteration.

  • this.handle(name: string) schedules the handler name to be executed with the item as parameter. As soon as this.handle() is called, the item is removed from the queue. Subsequent calls to this.handle() within the same function will schedule additional handlers for the same item.

var pickerId = sch.addPicker(function(item) {
  if (item % 2 === 0) {
    this.handle('something');
  }
  
  if (item === 42) {
    this.stop();
  }
});

It returns the pickerId, which can be used to modify the picker at runtime. This is mostly useful to adjust the interval or limit. A limit of 0 will disable the picker.

.start()

Start processing the queue. Useful if you need to do some preparation before firing things off but still want to be able to push things onto the queue.

.pickers

Access the array of pickers. This is useful to modify a picker, see above.

.started

You may want to know whether you've called start() yet. Or not.

Debug mode

Using debug: true in the instantiation config exposes both internal queues (todo and doing) and the handlers object. These are not useful for most cases, but if you need them they're just a flag away, no need to tweak shit.

Community

  • All authors and contributors are listed in the package.json.
  • Pull requests need to adhere to the style guide.
  • API is tested. Run npm test to ensure it works.
  • Code is linted. Run npm run-script lint to ensure you're good.
  • No license. This is released in the public domain.

Keywords

FAQs

Last updated on 07 Jul 2014

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