one-t-experiment
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

🥇 One Task (Test) 🥇

Rozhkov One Task tests Current npm package version.

Sequential running of tasks with a cancellation token

Installation

npm install one-task
# or
yarn add one-task

Usage

import oneTask from 'one-task';

const updateStateAsTransaction = async (cancellationToken) => {
  const rollback = async () => {/* restore state */};
  
  // asynchronous complex update
  
  if (cancellationToken.isCanceled) {
    await rollback();
    return;
  }
  
  // asynchronous complex update
}

const run = oneTask();
run(updateStateAsTransaction); // it will be called, but the token will be canceled
run(updateStateAsTransaction); // this task will be skipped
run(updateStateAsTransaction); // it will be run after completing the first task

API

interface ICancellationToken {
  readonly isCanceled: boolean;
}
type Task = (token: ICancellationToken) => Promise<void>;
type OneTask = (task: Task) => void;

👨‍💻 Author

Sergey Rozhkov

📄 License

Rozhkov One Task is MIT licensed, as found in the LICENSE file.

Package Sidebar

Install

npm i one-t-experiment

Weekly Downloads

2

Version

1.0.0

License

none

Unpacked Size

27.3 kB

Total Files

33

Last publish

Collaborators

  • rozhkov