Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-task-schedule

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-task-schedule - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

3

package.json
{
"name": "async-task-schedule",
"version": "0.1.2",
"version": "0.1.3",
"description": "schedule async tasks",

@@ -18,2 +18,3 @@ "main": "dist/index.js",

"schedule",
"task",
"async",

@@ -20,0 +21,0 @@ "dispatch"

@@ -8,2 +8,3 @@ # async-task-schedule

</a>
<img src="https://img.shields.io/badge/coverage-100%25-brightgreen" alt="use it with confident">
<a href="#readme">

@@ -39,5 +40,5 @@ <img src="https://badgen.net/badge/Built%20With/TypeScript/blue" alt="code with typescript" height="20">

```ts
import AsyncTask from 'async-task-schedule'
import TaskSchedule from 'async-task-schedule'
const asyncTask = new AsyncTask({
const taskSchedule = new TaskSchedule({
batchDoTasks: async (names: string[]) => {

@@ -49,6 +50,6 @@ count += 1

asyncTask.dispatch(['a', 'b']).then(console.log)
asyncTask.dispatch(['b', 'c']).then(console.log)
asyncTask.dispatch(['d', 'c']).then(console.log)
asyncTask.dispatch('c').then(console.log)
taskSchedule.dispatch(['a', 'b']).then(console.log)
taskSchedule.dispatch(['b', 'c']).then(console.log)
taskSchedule.dispatch(['d', 'c']).then(console.log)
taskSchedule.dispatch('c').then(console.log)
// batchDoTasks will be only called once

@@ -60,6 +61,6 @@

// batchDoTasks will be executed 3 times due to javascript language features
const result1 = await asyncTask.dispatch(['a', 'b'])
const result2 = await asyncTask.dispatch(['b', 'c'])
const result3 = await asyncTask.dispatch(['d', 'c'])
const result4 = await asyncTask.dispatch('c')
const result1 = await taskSchedule.dispatch(['a', 'b'])
const result2 = await taskSchedule.dispatch(['b', 'c'])
const result3 = await taskSchedule.dispatch(['d', 'c'])
const result4 = await taskSchedule.dispatch('c')
```

@@ -70,3 +71,3 @@

### constructor(options: IAsyncTask)
### constructor(options: ITaskScheduleOptions)

@@ -76,3 +77,5 @@ options define:

```ts
interface IAsyncTask {
// `Task` for single task's parameters
// `Result` for single task's response
interface ITaskScheduleOptions<Task, Result> {
/**

@@ -124,2 +127,3 @@ * action to do batch tasks, can be async or sync function

taskWaitingStrategy: 'throttle' | 'debounce'
/**

@@ -295,3 +299,3 @@ * task waiting time in milliseconds, default 50ms

const fetchSchedule = new AsyncTask({
const fetchSchedule = new TaskSchedule({
async doTask(cfg: {resource: string, options?: RequestInit}) {

@@ -342,3 +346,3 @@ return await fetch(cfg.resource, cfg.options)

const getUserAsyncTask = new AsyncTask({
const getUserSchedule = new TaskSchedule({
batchDoTasks: batchGetUsers,

@@ -350,4 +354,4 @@ // cache user info forever

const result = await Promise.all([
getUserAsyncTask.dispatch(['user1', 'user2']),
getUserAsyncTask.dispatch(['user3', 'user2'])
getUserSchedule.dispatch(['user1', 'user2']),
getUserSchedule.dispatch(['user3', 'user2'])
])

@@ -357,4 +361,4 @@ // only one request will be sent via getUsers with userIds ['user1', 'user2', 'user3']

// request combine won't works when using await separately
const result1 = await getUserAsyncTask.dispatch(['user1', 'user2'])
const result2 = await getUserAsyncTask.dispatch(['user3', 'user2'])
const result1 = await getUserSchedule.dispatch(['user1', 'user2'])
const result2 = await getUserSchedule.dispatch(['user3', 'user2'])
```

@@ -368,3 +372,3 @@

```ts
const asyncTask = new AsyncTask({
const taskSchedule = new TaskSchedule({
...,

@@ -371,0 +375,0 @@ taskExecStrategy: 'serial',

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc