npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

omnesiac

v0.0.6

Published

Mutually-Exclusive, Asynchronous Memoization

Downloads

3

Readme

(-_-)ゞ゛ Omnesiac

npm version Build Status codecov

Overview

A library implementing the marriage of two abstractions:

  • Mutual Exclusion
  • Memoization w/Time-to-Live

Concretely, this library was built to service two use-cases:

  • I need to perform some asynchronous work, throttled per unique key, and all subsequent calls using that key will block and await the result of that asynchronous work.
  • I need to perform some asynchronous work, throttled per unique key, and all subsequent calls using that key will continue without knowing the result of that asynchronous work.

tldr; a mutex-based throttling mechanism in blocking and non-blocking flavors.

Installation

Tested with >= Node.js 8.x

yarn add omnesiac

Usage

const Omnesiac = require('omnesiac');

async function doPeriodicAsynchronousWork(arg1, arg2) {
  /* 
    ...Do the deed...
  */
}

/*
 Memoize the results of this function for 30 seconds, and block subsequent calls while the asynchronous work is in-flight
*/
const throttledFn = Omnesiac(doPeriodicAsynchronousWork, { ttl: 30000, blocking: true });

const param1 = 'firstArgToTargetFunction';
const param2 = 'secondArgToTargetFunction';
const throttleKey = 'anyStringPerhapsAUserId';

/*
  The first call will execute the function. Subsequent calls using the same throttleKey will wait
  for the first call to finish and then resolve with the result of the first call for the next 30 seconds,
  whereupon, the next call will resume blocking until it has resolved, and on...
*/
const results = await throttledFn(throttleKey, param1, param2);

TODO

  • Better Documentation
    • Behavior
      • { ttl: 0 } = Never expire / cache forever
      • Resolution order of blocked calls not guaranteed
    • Real-world Use Cases
      • [Non-Blocking] Sample data collection, where approximate precision is good-enough
      • [Blocking] Cacheing burstable requests against shared resources
  • Timeouts on resolution of decorated function calls?
    • Maybe better to leave the onus on the function prior to Omnesiac decoration
    • Might make sense in the blocking scenario
  • Many more tests
    • Ensure proper scoping / garbage-collection aspects

Contributing

  1. Fork repo
  2. Add / modify tests
  3. Add / modify implementation*
  4. Open PR

* (Optional, but strongly encouraged) Link to your development soundtrack appending this README.md

License

MIT License

Copyright (c) 2020 Ombud

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Soundtrack

If you contribute to this library you are strongly encouraged to append your development soundtrack as a link to this README.md. One link per-PR, please, and it should be publicly, freely accessible (Youtube is a good option).

Francis Lai (Love Story Soundtrack) - Bozo Barrett

Lucio Battisti (Io tu noi tutti) - Amarsi un po'

Deodato - Also Sprach Zarathustra