function wait(delay) {
let promise;
const fn = function(result) {
return promise || (promise = new Promise(resolve => setTimeout(resolve, delay, result)));
};
fn.then = resolve => fn().then(resolve); // использование функции как thennable
return fn;
}