Socket
Socket
Sign inDemoInstall

@relax/async-utils

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @relax/async-utils

fully async implementations of common utility functions


Version published
Weekly downloads
372
increased by18.1%
Maintainers
1
Install size
1.57 MB
Created
Weekly downloads
 

Readme

Source

@relax/async-utils(1) -- async implementations of common utility functions

don't block

async-utils is designed to work with the async syntax to allow you to write non-blocking code that looks synchronous. functions like Array.prototype.map() are very useful, but operating over large collections will always block. async-utils rethinks a full range of useful tools to work with the event loop rather than against it.

contributors welcome! please email a patch or pull request to a maintainer and we'll get your changes merged as quickly as possible.

Modules

checksum
forEach
matchCase
memoize
microTask
pipe
Queue
to

Classes

Queue

Functions

checksum(...input)string

compute a the checksum of a javascript object.

forEach(collection, fn)
map(collection, fn)
matchCase()

type-directed pattern matching. compares input with the given types via instanceof.

const [err, result] = await to(myAsyncFn())
cosnt returnValue = matchCase(err,
  [TypeError, () => {
    // handle TypeError
  }],
  [HttpError, () => {
    // handle HttpError
  }],
  () => {
    // ifNoneMatch, handle result
  }
)
Memoize([identity])function

cache namespace cosntructor the passed identity function is used to track which function made a particular call so it can be associated with the cache. by default, memoize uses the included checksum function.

microTask(fn)

schedule a task to run on nextTick

pipe(predicate, fns)Promise.<any>

execute a chain of async operations using the return value of each function as the argument for the next

to()

simplify error checking for async processes. promotes shorter code with explicit error handling up front.

const [err, result] = await to(myAsyncFn())
if (err) {
  // handle error
} else {
  // happy path
}

compared to the usual try..catch approach. these are simple contrived examples, but in complex async processes the resulting code is typically more linear, with less nested branches compared to the typical approach. we give up the narrow error handling scope and handling errors is always deferred until later by the grammar.

try {
  const result = await myAsyncFn()
  // happy path
} catch (err) {
  // handle error
}

checksum

checksum(...input) ⇒ string

compute a the checksum of a javascript object.

Kind: global method of checksum

ParamTypeDescription
...input*

any javascript object

forEach

forEach(collection, fn) ⏏

Kind: global method of forEach

ParamType
collectionarray
fnfunction

matchCase

matchCase() ⏏

type-directed pattern matching. compares input with the given types via instanceof.

const [err, result] = await to(myAsyncFn())
cosnt returnValue = matchCase(err,
  [TypeError, () => {
    // handle TypeError
  }],
  [HttpError, () => {
    // handle HttpError
  }],
  () => {
    // ifNoneMatch, handle result
  }
)

Kind: global method of matchCase

memoize

Memoize([identity]) ⇒ function

cache namespace cosntructor the passed identity function is used to track which function made a particular call so it can be associated with the cache. by default, memoize uses the included checksum function.

Kind: global method of memoize
Returns: function -

cache instance


See: checksum

ParamTypeDescription
[identity]function

optional identity function

Memoize~memoize(fn, args, ttl)

cache the result of a function call in memory.

Kind: inner method of Memoize

ParamTypeDescription
fnfunction

the function that is being memoized

argsarray

arguments that should be passed into fn

ttlnumber | Object

time to live value and cache group

memoize.clear(cacheGroup)

evict a group of cached objects

Kind: static method of memoize

ParamType
cacheGroupstring

microTask

microTask(fn) ⏏

schedule a task to run on nextTick

Kind: global method of microTask

ParamType
fnfunction

pipe

pipe(predicate, fns) ⇒ Promise.<any>

execute a chain of async operations using the return value of each function as the argument for the next

Kind: global method of pipe

ParamType
predicateany
fnsArray.<function(value)>

Queue

Queue ⏏

Kind: global class of Queue

to

to() ⏏

simplify error checking for async processes. promotes shorter code with explicit error handling up front.

const [err, result] = await to(myAsyncFn())
if (err) {
  // handle error
} else {
  // happy path
}

compared to the usual try..catch approach. these are simple contrived examples, but in complex async processes the resulting code is typically more linear, with less nested branches compared to the typical approach. we give up the narrow error handling scope and handling errors is always deferred until later by the grammar.

try {
  const result = await myAsyncFn()
  // happy path
} catch (err) {
  // handle error
}

Kind: global method of to
See: module:matchCase

Keywords

FAQs

Last updated on 01 Feb 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc