npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

async-task-mapping

v1.0.5

Published

Asynchronous Task Manager.

Downloads

16

Readme

async-task-mapping

It can make asynchronous tasks that promise cannot complete, ignore the order of sending and receiving, allow binding of asynchronous tasks in pending status, allow triggering a task in multiple functions, and support producer consumer mode and order mode.

English | 简体中文

Pre-requisites

The async-task-mapping library does not use any third-party dependency packages and does not limit the technology stack.

Install

npm i async-task-mapping --save

Usage

use createTaskList

version

import { createTaskList } from "async-task-mapping";
const asyncTask = createTaskList({
  ordered: true,
  taskCount: 2,
  resolveCount: 2,
});

setTimeout(async () => {
  // A Promise.resolve is returned here. You can use either async/await or .then.
  const { list, dataMap } = await asyncTask;
  console.log("data-1", list[0]);
  // or
  asyncTask.then(({ list, dataMap }) => {
    console.log("data-1", list[0]);
  });
}, 100);

setTimeout(async () => {
  const { list, dataMap } = await asyncTask;
  console.log("data-2", dataMap.res2);
}, 200);

setTimeout(() => {
  asyncTask.pushResolve("response1");
}, 300);

setTimeout(() => {
  asyncTask.pushResolve("response2", "res2");
}, 400);

You can use these functions in different methods. The result of the above code is:

// time 200: request-2
// time 300: data-1 response1
// time 400: data-2 response2

Parameters passed in during createTaskList instantiation

| name | description | default | | ------------ | ------------------------------------ | ------- | | ordered | Is it orderly | false | | taskCount | Number of times to access data | 1 | | resolveCount | Increase the number of times of data | 1 |

Methods on createTaskList Instances

| name | description | returned data structure | | ----------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | then* | The original method of promise | task.then(({list, dataMap})=>{}) | | pushResolve | Used to add data | pushResolve(data, name), Not required, data of Promise.resolve | | clear | Clear all statuses | -- | | paused | pause task | -- | | running | continue matching tasks | -- | | getStatus | Get current status | {  // Whether to complete all request binding    requestDone: false,   // Whether to complete all pushResolve   responseDone: false,    //Number of requests bound    requestCount: 1 (Number of requests bound),    // Number of pushResolve complete  responseCount: 1 (Number of pushResolve completed)} |

use createTaskOrder

The request and response can be out of order.

import { createTaskOrder } from "async-task-mapping";
const taskOrder = createTaskOrder();

setTimeout(async () => {
  // A Promise.resolve is returned here. You can use either async/await or .then.
  const data = await taskOrder;
  console.log("data1", data);
}, 230);

setTimeout(async () => {
  const data = await taskOrder;
  console.log("data2", data);
}, 500);
setTimeout(() => {
  taskOrder.pushResolve("resolve1");
}, 200);
setTimeout(() => {
  taskOrder.pushResolve("resolve2");
}, 300);
setTimeout(() => {
  taskOrder.pushResolve("resolve3");
}, 400);

You can use these functions in different methods. The result of the above code is:

// time 230: data1 resolve1
// time 500: data2 resolve2

Methods on createTaskOrder Instances

| name | description | returned data structure | | -------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | pushResolve | Used to add data | -- | | clear | Clear all statuses | -- | | paused | pause task | -- | | running | continue matching tasks | -- | | getStatus | Get current status | {  //Number of incomplete matching requests  pendingRequests: 0,   //Number of responses that have not completed matching  pendingResponses: 0 } | | getLastCompletedTask | Get the data matching the last request with the response | -- |

License

MIT.