New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

aah

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aah

A library of async/await helpers

latest
Source
npmnpm
Version
1.1.2
Version published
Maintainers
1
Created
Source

aah

A JavaScript library of async/await helpers

aah : object

Kind: global namespace

aah.Callbackify ⇒ function

	const task = Callbackify(
		async (i) => i + 1
	);

	// logs 'res 1', eventually
	task(
		(err, res) => console.log('res', res),
		0
	);

Kind: static property of aah
Returns: function - a callback-expecting function
Params

  • task function - an async function

aah.CatchError ⇒ function

  let task = CatchError(task);

  const { error, result } = await task(request);

Kind: static property of aah
Returns: function - an async wrapper function around the task
Params

  • task function - an async function to wrap around with a catch wrapper.

aah.Delay ⇒ function

	const task = Delay(1000);

	const result = await task(1); // result is 1, after 1 second

Kind: static property of aah
Returns: function - an async function
Params

  • time number - the time to delay

aah.InOrder ⇒ function

	const task = InOrder(
		async (i) => i + 1,
		async (i) => i + 1,
		async (i) => i + 1
	);

	const results = await task(0); // results is 3

Kind: static property of aah
Returns: function - an async wrapper function that runs all of the tasks in order, calling each one with original request
Params

  • ...tasks function - any number of async tasks.

aah.InParallel ⇒ function

	const task = InParallel(
		async (i) => i + 1,
		async (i) => i + 2,
		async (i) => i + 3
	);

	const results = await task(0); // results is [1, 2, 3]

Kind: static property of aah
Returns: function - an async wrapper function that runs all the tasks in parallel, and returns an array of results
Params

  • ...tasks function - any number of async tasks.

aah.InSeries ⇒ function

	const task = InSeries(
		async (i) => i + 1,
		async (i) => i + 1,
		async (i) => i + 1
	);

	const results = await task(0); // results is 3

Kind: static property of aah
Returns: function - an async wrapper function that runs all of the tasks in series, calling each one with the results of the previous one
Params

  • ...tasks function - any number of async tasks.

aah.ParallelFilter ⇒ function

	const task = ParallelFilter(
		async (val, i) => val % 2 === 0
	);

	const results = await task([0, 1, 2]); // results is [0, 2]

Kind: static property of aah
Returns: function - an async wrapper function that takes in an array of requests, runs the task in parallel, once for each input in the array, and returns an array of results
Params

  • task function - the filtering task

aah.ParallelMap ⇒ function

	const task = ParallelMap(
		async (val, i) => val + 1
	);

	const results = await task([0, 1, 2]); // results is [1, 2, 3]

Kind: static property of aah
Returns: function - an async wrapper function that takes in an array of requests, runs the task in parallel, once for each input in the array, and returns an array of results
Params

  • task function - the mapping task

aah.PassThrough

	const task = PassThrough;

	const results = await task(0); // results is 0

PassThrough does nothing, just passes the request through as the result

Kind: static property of aah

aah.Promisify ⇒ function

	const task = Promisify(
		(onDone, i) => onDone(
			i === 0 ? new Error('i cant be 0') : null,
			i + 1
		),
	);

	const results = await task(1); // results is 2
	const results2 = await taks(0); // throws 'i cant be 0 Error

Kind: static property of aah
Returns: function - an async function
Params

  • task function - a callback-expecting function

aah.Race ⇒ function

	const task = Race(
		async (i) => i + 1,
		async (i) => i + 2,
	);

	const result = await task(1); // 2

Kind: static property of aah
Returns: function - an async task that resolves or rejects as soon as the first one of its "children" resolves or rejects
Params

  • ...tasks function - any number of async tasks

aah.TimeIn ⇒ function

	const task = TimeIn(async (i) => i + 1, 1000);

	const result = await task(1); // result1 = 2, after 1000 ms

Kind: static property of aah
Returns: function - an async task
Params

  • task function - an async task
  • timeIn function - the minimum time the task can take

aah.TimeOut ⇒ function

	const task1 = TimeOut( Delay(100), 1000);
	const task2 = TimeOut( Delay(1000), 100);

	const result1 = await task1(1); // result1 = 1, after 100 ms
	const result2 = await task2(1); // throws a timeout error after 100 ms

Kind: static property of aah
Returns: function - an async task
Params

  • task function - an async tasks
  • timeOut function - the number of ms before throwing an error

aah.Assert(validator, message) ⇒ taskFunction

Builds an async assertion task. When called, if the arguments do not match the validator functions,

Kind: static method of aah
Returns: taskFunction - an assertion task
Params

  • validator function - a function that checks the request.
  • message string - an optional error message to throw if the assertion fails, or a message builder function.

aah.Logging(...statements) ⇒ function

A logging utility. It passes the request received into all the statements, collects the results, and pushes them into console.log

Kind: static method of aah
Returns: function - a logging task
Params

  • ...statements * - any number of logging values. Functions are called with the calling request, everything else is passed directly to

Keywords

async

FAQs

Package last updated on 18 Oct 2018

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