import { Operation } from '../operation' ; import { createFuture } from '../future' ; import { withLabels } from '../labels' ; param duration export function sleep ( duration ? ) { return withLabels ( ( task ) => { let { future , resolve } = createFuture < void > ( ) ; if ( duration != null ) { let timeoutId = setTimeout ( resolve , duration ) ; task . consume ( ( ) => clearTimeout ( timeoutId ) ) ; } return future ; } , { name : 'sleep' , duration : ( duration != null ) ? duration : 'forever' } ) ; }