@effection/core
Advanced tools
Comparing version 2.0.0-preview.0-60173ef to 2.0.0-preview.0-f6f223c
{ | ||
"name": "@effection/core", | ||
"version": "2.0.0-preview.0-60173ef", | ||
"version": "2.0.0-preview.0-f6f223c", | ||
"main": "dist/index.js", | ||
@@ -20,5 +20,5 @@ "types": "dist/index.d.ts", | ||
"ts-node": "^8.8.2", | ||
"tsdx": "^0.14.0", | ||
"tsdx": "0.13.2", | ||
"typescript": "^3.8.3" | ||
} | ||
} |
import { Operation } from './operation'; | ||
export function sleep(duration: number): Operation<void> { | ||
return (task) => (resolve) => { | ||
let timeoutId = setTimeout(resolve, duration); | ||
task.ensure(() => { | ||
return function*() { | ||
let timeoutId; | ||
try { | ||
yield new Promise((resolve) => { | ||
setTimeout(resolve, duration); | ||
}); | ||
} finally { | ||
if(timeoutId) { | ||
clearTimeout(timeoutId); | ||
} | ||
}); | ||
} | ||
} | ||
} |
34378
1044