eno/fetch.test.tsx

35 lines
782 B
TypeScript
Raw Normal View History

2023-04-18 22:22:59 -04:00
import {Fetch} from "./lib/iso.tsx";
const delay =async(inHandler:()=>void, inDelay:number):Promise<void>=>
{
return new Promise((accept)=>{
setTimeout(()=>{
accept(inHandler());
}, inDelay);
});
};
2023-04-20 21:07:26 -04:00
const queue = [1, 2, 3];
while(queue.length)
{
await(delay(()=>{console.log(queue.pop())}, 1000))
}
2023-04-19 20:56:30 -04:00
2023-04-20 21:07:26 -04:00
console.log("all done!");
2023-04-19 20:56:30 -04:00
/*
2023-04-18 22:22:59 -04:00
let r1, r2, r3;
delay(()=>{r1 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r1); }, 10);
delay(()=>{r2 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r2); }, 20);
delay(()=>{r3 = Fetch.Request(`https://catfact.ninja/fact`, undefined, 0.2); console.log(r3); }, 2000);
await delay(()=>{}, 3000);
console.log(r1);
console.log(r2);
2023-04-19 20:56:30 -04:00
console.log(r3);
*/