
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@relax/async-utils
Advanced tools
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.
string
⏏compute a the checksum of a javascript object.
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
}
)
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.
schedule a task to run on nextTick
Promise.<any>
⏏execute a chain of async operations using the return value of each function as the argument for the next
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
}
string
⏏compute a the checksum of a javascript object.
Kind: global method of checksum
Param | Type | Description |
---|---|---|
...input | * | any javascript object |
Kind: global method of forEach
Param | Type |
---|---|
collection | array |
fn | function |
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
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
Param | Type | Description |
---|---|---|
[identity] | function | optional identity function |
cache the result of a function call in memory.
Kind: inner method of Memoize
Param | Type | Description |
---|---|---|
fn | function | the function that is being memoized |
args | array | arguments that should be passed into fn |
ttl | number | Object | time to live value and cache group |
evict a group of cached objects
Kind: static method of memoize
Param | Type |
---|---|
cacheGroup | string |
schedule a task to run on nextTick
Kind: global method of microTask
Param | Type |
---|---|
fn | function |
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
Param | Type |
---|---|
predicate | any |
fns | Array.<function(value)> |
Kind: global class of Queue
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
FAQs
fully async implementations of common utility functions
The npm package @relax/async-utils receives a total of 276 weekly downloads. As such, @relax/async-utils popularity was classified as not popular.
We found that @relax/async-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.