import { Effection , Operation , Resource , sleep , spawn } from '../src/index' ; import { beforeEach } from 'mocha' ; beforeEach ( async ( ) => { await Effection . reset ( ) ; } ) ; export function createNumber ( value ) { return function * ( ) { yield sleep ( 1 ) ; return value ; } ; } export function * blowUp ( ) { yield sleep ( 1 ) ; throw new Error ( 'boom' ) ; } export function * asyncResolve ( duration , value ) { yield sleep ( duration ) ; return value ; } export function * asyncReject ( duration , value ) { yield sleep ( duration ) ; throw new Error ( `boom: ${ value }` ) ; } export function * syncResolve ( value ) { return value ; } export function * syncReject ( value ) { throw new Error ( `boom: ${ value }` ) ; } export function asyncResource ( duration , value , status ) { return { * init ( ) { yield spawn ( function * ( ) { yield sleep ( duration + 10 ) ; status . status = 'active' ; } ) ; yield sleep ( duration ) ; return value ; } } ; }