Skip to content

mabels/scopey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scopey

JS/TS Implementation for better try/catch/finally handling

Full example in: https://github.com/mabels/scopey/blob/main/ts/smoke/smoke.ts

const rsc = await scopey(async (scope) => {
    const fileHdl = await scope
      .eval(async () => {
        return await open("temp-smoke.txt", "w");
      })
      .cleanup(async (hdl) => {
        await hdl.write("EOF");
        await hdl.close();
      })
      .do();
    for (let i = 0; i < 100; i++) {
      await scope
        .eval(async () => {
          return await fileHdl.write(`Hello, World! ${i}\n`);
        })
        .finally(async () => {
          await fileHdl.write(`Final, World! ${i}\n`);
        })
        .do();
    }
    return "OK";
  });

About

JS/TS Implementation for better try/catch/finally handling

Resources

License

Stars

Watchers

Forks

Packages

No packages published