@aliclark/tasklets
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Tasklets

import { make, gather, Tasklet } from '@aliclark/tasklets'

const homeId = 42

interface House {
    kitchenId: string
    loungeId: string
}

interface Home {
    house: House
    kitchen: string
    lounge: string
}

const getHouse: Tasklet<House> = make(done => setTimeout(() => done({ kitchenId: `${homeId}k`, loungeId: `${homeId}l`}), 1))

// The unhandled error will be console.warn'd
make(done => { console.log('logging something'); done(new Error('some logging error')) })

const getHome: Tasklet<Home> = gather({
    house:   getHouse,
    kitchen: getHouse.and(({ kitchenId }) => then => setTimeout(() => then(`kitchen ${kitchenId}`), 1)),
    lounge:  getHouse.and(({ loungeId  }) => then => setTimeout(() => then(`lounge ${loungeId}`),   1))
})

await getHome.or(error => otherwise => {
    console.error('failed to get the home')
    otherwise(error)
})
yarn add @aliclark/tasklets

Readme

Keywords

none

Package Sidebar

Install

npm i @aliclark/tasklets

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

28.5 kB

Total Files

13

Last publish

Collaborators

  • aliclark