Giter Club home page Giter Club logo

rubidium's Introduction

rubidium

Rubidium is a one-time task emitter, inspired by the unix at utility. This module is a minimal implementation. It exports a constructor. Instances of the constructor are event emitters, with methods to add and remove job specifications. A job consists of a due time and a message.

Rubidium is built upon the use of setTimeout, so the usual warnings apply. That said, Rubidium creates a fresh timeout after each job is emitted, so it is self-correcting to within the resolution of a timer.

Rubidium is built on vetebrate-event-emitter, which makes it robust against memory leaks. It has been bundled for you with its dependencies, so Rubidium has no dependencies in production.

Usage

A brief example is given below. See the examples directory for some more interesting examples, including wrapping a rubidium instance in an HTTP server, and persisting a rubidium instance over app restarts.

import Rubidium from 'rubidium';

var rb = new Rubidium();

rb.on('job', job => console.log(job.message));

// Add a job to be emitted in 5 seconds time.
rb.add({ time: Date.now() + 5000, message: '5 seconds have passed.' });

// Add a job to be emitted in one day.
rb.add({ time: Date.now() + 1000 * 60 * 60 * 24, 'One day as passed.' });

You could of course do this with vanilla timeouts. A rubidium instance allows you to do it all with a single timeout. It also works around the maximum timeout length, so you can have a job more than about 25 days into the future.

API

Rubidium extends vertebrate-event-emitter, so please see the docs for that for the base API around events (methods like on, off etc.)

var rb = new Rubidium()

Construct a new Rubidium instance.

var hasJobs = rb.hasPendingJobs

A boolean property. True when there are jobs remaining in the queue.

var job = rb.add({ time, message, [uuid] }, silent)

Add a job. The time must be a Date instance or a timestamp integer (like Date.now()) representing the time for the job to be emitted. This method returns a job with a uuid property that may be used to find or remove the job from the queue.

When uuid is in the spec, it will be copied into the job. This is useful for reviving a persisted queue (see the section on persistence below). In general, you should not be setting this.

When silent is true, this addJob event will not be emitted. This is useful for reviving a persisted queue.

var job = rb.remove(uuid, silent)

Remove a job from a Rubidium instance with the job uuid. This function returns a job if the job existed and was removed, or undefined if the job did not exist. When silent is true, the removeJob event will not be emitted.

var job = rb.find(uuid)

Get a job from the Rubidium instance with the job uuid. Returns undefined when no matching job is found.

rb.clear(silent)

Clear all pending jobs. When silent is true, the clearJobs event will not be emitted.

Event: 'job'

Listeners on the 'job' event receive a job object containing time and message fields, where time is an integer.

Event: 'addJob'

This event is emitted when a new job is added. The job object is passed as an argument to listeners on this event.

Event: 'removeJob'

This event is emitted when when a job is removed. The job object is passed as an argument to listeners on this event. When the clear method is used, this event is emitted for every job.

Event: 'clearJobs'

This event is emitted when all jobs for a Rubidium instance are cleared.

rubidium's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar qubyte avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rubidium's Issues

An in-range update of sinon is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 4.4.7 of sinon was just published.

Branch Build failing 🚨
Dependency sinon
Current Version 4.4.6
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 7 commits.

  • e060fe9 Update docs/changelog.md and set new release id in docs/_config.yml
  • e9fce06 Add release documentation for v4.4.7
  • f047838 4.4.7
  • cc91fe6 Update History.md and AUTHORS for new release
  • 9fb8577 Emojify the support message :heart:
  • a87ef85 Use existing mini-lib for coloring
  • 1f33fe5 Reduce noisy NPM output from postinstall script

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.9.2 to 1.9.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: lint: Your tests failed on CircleCI (Details).
  • ci/circleci: test: Your tests failed on CircleCI (Details).

Release Notes for v1.9.3

2019-04-10

Bug Fixes

  • Simplify return expressions that are evaluated before the surrounding function is bound (#2803)

Pull Requests

  • #2803: Handle out-of-order binding of identifiers to improve tree-shaking (@lukastaegert)
Commits

The new version differs by 3 commits.

  • 516a06d 1.9.3
  • a5526ea Update changelog
  • c3d73ff Handle out-of-order binding of identifiers to improve tree-shaking (#2803)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of sinon is breaking the build 🚨

Version 4.1.6 of sinon was just published.

Branch Build failing 🚨
Dependency sinon
Current Version 4.1.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 10 commits.

  • 68c37ed Update docs/changelog.md and set new release id in docs/_config.yml
  • cd8ae51 Add release documentation for v4.1.6
  • 29e80be 4.1.6
  • a5c59a5 Update History.md and AUTHORS for new release
  • 0ae60b6 Merge pull request #1653 from mroderick/upgrade-dependencies
  • dcd4191 Upgrade browserify to latest
  • a316f02 Upgrade markdownlint-cli to latest
  • 78ebdb3 Upgrade lint-staged to latest
  • fcf967b Upgrade dependency supports-color
  • 7c3cb4f Enable StaleBot with default configuration (#1649)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.14.2 to 1.14.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: test: Your tests failed on CircleCI (Details).
  • ci/circleci: lint: Your tests failed on CircleCI (Details).

Release Notes for v1.14.3

2019-06-06

Bug Fixes

  • Generate correct external imports when importing from a directory that would be above the root of the current working directory (#2902)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.