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

remembered

v0.11.0

Published

Easy memory cache and semaphore

Downloads

1,080

Readme

Actions Status Actions Status Actions Status Test Coverage Maintainability Packages npm version

A module to remember for a given time the promises you made.

How to install

npm install remembered

Usage

Create a new Remembered instance giving the ttl you want, in ms.

const remembered = new Remembered({ ttl: 1000 });

Now, just call the get method informing a remembering key and a callback:

const callback = () => new Promise<number>((resolve) => {
  setTimeout(200, () => resolve(Date.now()));
});

const [r1, r2, r3] = await Promise.all([
  remembered.get('test', callback),
  remembered.get('test', callback),
  remembered.get('test', callback),
]);

In the above example, r1, r2 and r3 will receive the same exact +promise. Remembered don't "cache" the result of your async operation: it caches the promise itself.

This is very useful for concurrent tasks where you have the same heavy call and you want it to happen just once. In this example, the promise is resolved in 200 milliseconds, but the ttl is 1 second and it starts to count not after the promise is resolved, but when the promise is made. In other words, exactly 1 second after the first call, the callback will need to be called again.

If you want for the promise to be remembered just while it is not resolved, you can use ttl 0. In this case, while the promise is pending, Remembered will return the same reference, but, after it is resolved, then callback will be called

Another option is to use the wrap method:

const callback = () => new Promise<number>((resolve) => {
  setTimeout(200, () => resolve(Date.now()));
});
const wrapped = remembered.wrap(callback, () => 'test');

const [r1, r2, r3] = await Promise.all([
  wrapped(),
  wrapped(),
  wrapped(),
]);

The wrap method returns a version of your function that receives the exact same arguments, but uses remembered under the hood. The second parameters you inform also receives the same parameters that your first callback receives, but it must return the remembering key.

Important!

The given ttl is meant to be readonly. So, if you change the ttl value of the provided, it will not take effect on the previous Remembered instances.

Saudade

There is no proper translation for the word saudade in English. Saudade is the feeling that you feel when you miss someone. It's the emptiness that is left when someone important to you passes away. This module is a tribute for my dear uncles who died due to complications of COVID-19. Uncles, you'll always be remembered.

  • ✞ 2020-04-01: Genivaldo Rodrigues dos Santos
  • ✞ 2020-03-21: João Carlos Rodrigues dos Santos

License

Licensed under MIT.