0.1.0 • Published 6 years ago

dark-aigle v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Dark-Aigle

Dark Aigle has dark power.

The library extends a native Promise or a Promise library to have Aigle functions.

It is mainly used for a native Promise because of Async/Await restrictuion. See Example.

Usage

You just need to call this library somewhere. The Promise will be extended.

require('dark-aigle')(Promise);

Example

async function executeAsyncTask() {
  await new Promise(resolve => setTimeout(resolve));
}

async function getArray() {
  await executeAsyncTask();
  return [1, 2, 3];
}

async function filterIterator(num) {
  await executeAsyncTask();
  return num % 2 === 1;
}

async function mapIterator(num) {
  await executeAsyncTask();
  return num * 2;
}
test();

async function test() {
  const array = await getArray();
  const boolList = await Promise.all(array.map(filterIterator));
  const filtered = array.filter((n, i) => boolList[i]);
  const result = await Promise.all(filtered.map(mapIterator));
  console.log(result); // [2, 6]
}

If you use the library, you can make it simple and readable.

requrie('dark-aigle')(Promise);

test();

async function test() {
  const result = await getArray()
    .filter(filterIterator)
    .map(mapIterator);
  console.log(result); // [2, 6]
}