1.1.0 • Published 3 years ago

@aliclark/tasklets v1.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

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
1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago