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

@kikobeats/cold-start

v1.0.6

Published

Create lazy singleton functions with cold-start capabilities.

Downloads

20

Readme

cold-start

Last version Build Status Coverage Status NPM Status

Create lazy singleton functions with cold-start capabilities.

Why

A cold start is the first time your code has been executed in a while (5–25minutes).

This concept has been using for some infrastructure providers, such as:

  • AWS Lambda shutting down λ functions after an inactivity time.
  • Heroku Dynos sleeping instances after 30 minutes no web traffic activity.

This library brings you this concept to be applied to any piece of software, like:

  • Keep up a pool of servers where actually just a few of them are actively used.
  • Keep expensive process running that most of the time it isn't being used.
  • Wrap some sensible pieces of code that need to be restarted after a while.

The mission of the library is to keep on sync machine resources with real usage.

It's specially useful when you want to shutdown a long-time process that actually is not being used, cutting down infrastructure costs.

Install

$ npm install @kikobeats/cold-start --save

Usage

const coldStart = require('@kikobeats/cold-start')()
const createBrowserless = require('browserless')
const ms = require('ms')

const getBrowserless = coldStart({
  // every cold start function need to have an unique name
  name: 'browserless',
  // setup lazy intialization, it should be return something to be use into succesive calls
  start: createBrowserless,
  // setup teardown, if it's necessary
  stop: browserless => browserless.destroy(),
  // how much idle time to consider the function can be stopped.
  duration: ms('5m')
})

;(async () => {
  // first call will initialize the cold start function
  await getBrowserless()

  // succesive calls will reuse the instance
  await getBrowserless()

  // If the cold start function is not being called in a time window of 5m,
  // the cold start function will be destroyed.
  // The first call after that will allocate it again
  await getBrowserless()
})()

API

createColdStart([options])

It creates a new cold start storage, returning a function to be used for registering any cold start over the storage.

options

store

Type: object Default: {}

It sets the storage to be used for keeping cold start functions running on background.

After initialization, store can be accessed by .store instance method.

shutdown

Type: boolean Default: false

It sets the logic to run for shutting down all the cold start functions running.

After initialization, shutdown method can by .shutdown instance method.

coldStart([options])

It register a new cold start function into the associated storage

options

name

Required Type: string

An unique name for identifying the cold start function.

start

Required Type: function

The function to be executed in order of getting the value to be retrieved into the successive function calls.

stop

Required Type: function

A teardown function to be executed before shutdown the cold start function.

duration

Required Type: number

How much idle time can be considered a cold start function is inactive and should be shutting down.

License

@kikobeats/cold-start © Kiko Beats, released under the MIT License. Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @kikobeats