@types/thunky

  • Version 1.1.2
  • Published
  • 3.97 kB
  • No dependencies
  • MIT license

Install

npm i @types/thunky
yarn add @types/thunky
pnpm add @types/thunky

Overview

TypeScript definitions for thunky

Index

Functions

Functions

function thunky

thunky: <TFn extends (callback: (...args: any[]) => any) => void>(
fn: TFn
) => TFn;
  • Delay the evaluation of a paramless async function and cache the result (see [thunk](http://en.wikipedia.org/wiki/Thunk_%28functional_programming%29)).

    If the thunk callback is called with an Error object as the first argument it will not cache the result.

    Parameter fn

    The function to execute.

    Example 1

    import thunky = require('thunky');

    const test = thunky((callback) => { // the inner function should only accept a callback console.log('waiting 1s and returning random number'); setTimeout(() => { callback(Math.random()); }, 1000); });

    test((num) => { // inner function is called the first time we call test console.log(num); // prints random number });

    test((num) => { // subsequent calls waits for the first call to finish and return the same value console.log(num); // prints the same random number as above });

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (0)

No dev dependencies.

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/thunky.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/thunky)
  • HTML
    <a href="https://www.jsdocs.io/package/@types/thunky"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>