import { Operation } from '../operation' ; import { Future } from '../future' ; param fn export function ensure < T > ( fn ) { return function ensure ( task ) { let { scope } = task . options ; if ( ! scope ) { throw new Error ( 'cannot run `ensure` on a task without scope' ) ; } scope . run ( function * ensureHandler ( ) { try { yield ; } finally { let result = fn ( ) ; if ( result ) { yield result ; } } } ) ; return Future . resolve ( undefined ) ; } ; }