🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

chainik

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainik

Simple helper for building async chainable classes without external dependencies

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

chainik

Motivation

Simple helper for building async chainable classes without external dependencies

Chainik means teapot in Russian. I took this name because it associated with chains and cantik, which means beautiful in Indonesian and some other languages. Also, other names containing chain word and suitable for this module was occupied in NPM.

Features

  • Typescript types out of the box
  • No external dependencies
  • Works in browser and node
  • Simple

Installation

npm i -g chainik

For usage, see example below (more examples and documentation coming soon!):

import Chainik from 'chainik'

const delay = (t: number) => new Promise(r => setTimeout(r, t))

type Data = string[]
type Params = { foo: string }

class Chainable extends Chainik<Data, Params> {
  step1(d: number) {
    console.log('queued step1')
    return this.queue(async () => {
      await delay(d)
      this.data.push('step1')
      console.log('executed step1')
    })
  }

  step2(d: number) {
    console.log('queued step2')
    return this.queue(async () => {
      await delay(d)
      this.data.push('step2')
      console.log('executed step2')
    })
  }

  step3() {
    console.log('queued step3')
    return this.queue(() => {
      // Using params from constructor as context
      this.data.push(`using ctor param: ${this.params.foo}`)
      console.log('executed step3')
    })
  }
}

async function main() {
  console.log('started')

  const chain = new Chainable([], { foo: 'bar' })
  const data = await chain.step1(1000).step2(2000).step3().exec()

  console.log('data: ', data)
}

if (require.main === module) {
  main()
}

Keywords

promise

FAQs

Package last updated on 01 Oct 2020

Did you know?

Socket

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