# chainable-tasks

> Like native JavaScript promises, this library is designed to work with a large number of chained asynchronous requests involved with business rules and data return in a simple way.

Latest version **1.0.2** (published 2017-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install chainable-tasks
pnpm add chainable-tasks
yarn add chainable-tasks
bun add chainable-tasks
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-09-29 |
| First published | 2017-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ricardo Azzi Silva |
| Maintainers | lordazzi |
| Keywords | chained, chainable, asynchronous, promises, multiple, task, tasks, js, ts, typescript, javascript, simple |

## Links

- npm: https://www.npmjs.com/package/chainable-tasks
- Repository: https://github.com/lordazzi/chainable-tasks
- Homepage: https://github.com/lordazzi/chainable-tasks#readme
- Issues: https://github.com/lordazzi/chainable-tasks/issues
- npm.io page: https://npm.io/package/chainable-tasks

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.2 (latest) — 2017-09-29

## README

# Tasks
Like native JavaScript promises, this library is designed to work with a large number of chained asynchronous requests involved with business rules and data return in a simple way.

Assim como os promises nativos de JavaScript, esta biblioteca foi desenhada para trabalhar com uma grande quantidade de requisições assíncronas encadeadas envolvendo regras de negócio e retorno de dados de uma forma simples.

    var tarefas = new Tasks.Task(function(yes, no){
         setTimeout(function(){
         	yes('love potatoes');
         }, 1000);
    }).then(function(yes, no, anything){
         console.info(anything);
         setTimeout(function(){
         	yes(anything + ' and bacon');
         }, 1000);
    }).then(function(yes, no, anything){
         console.info(anything);
         setTimeout(function(){
         	throw "error message";
         }, 1000);
    });
    
    //  see that the next task will be bind to the first one generated,
    //  but this will not change the execution order, internally this
    //  new task will be created as the last task son
    tarefas.then(function(yes, no, anything){

         // this one never will be executed because the last task is
         // lauching an exception so, the catch will be activated 
         console.info(anything);
         setTimeout(function(){
         	yes(anything + ' and onion rings');
         }, 1000);
    }).catch(function(err){
         console.error(err.message);
    });

Add new tasks in the end using the original task or some one other in the middle will help you join multiples requests and return something like a promise with data access to the programmer continue working with tasks, like this:

    var dao = {
        getProduct: (data) => {
            return new Tasks.Task((next, stop) => {
    
                $.ajax({
                    url:    "product/infos"
    
                    data:   data,
    
                    method: 'GET',
    
                    success(infos){
                        next({ 
                            type:         infos.type,
                            name:         infos.name,
                            description:  infos.description
                        });
                    },
    
                    failure(err){
                        stop(err);
                    }
                });
    
            }).then(function(next, stop, dataFromOtherRequest){
    
                $.ajax({
                    url:    "product/images"
                    
                    data:   { type: dataFromOtherRequest.type },
    
                    method: 'GET',
    
                    success(prices){
                        dataFromOtherRequest.prices = prices;
                        next(dataFromOtherRequest);
                    },
    
                    failure(err){
                        stop(err);
                    }
                });
    
            }).then(function(next, stop, dataFromOtherRequest){
    
                $.ajax({
                    url:    "product/images"
                    
                    data:   data,
    
                    method: 'GET',
    
                    success(images){
                        dataFromOtherRequest.images = images;
                        next(dataFromOtherRequest);
                    },
    
                    failure(err){
                        stop(err)
                    }
                });
    
            });
        }
    };
    
    dao.getProduct({ code: 1000 }).then((go, dontgo, data) => {
    
        // display data in screen or anothor stuff
    
    }).catch(e => {
        alert(e.message);
    });

---
_Source: https://npm.io/package/chainable-tasks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
