import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/dialog/progress.js";
Displays a dialog with a progress bar indicating the ongoing state of the
fn
function, and to wait until the job finishes or the user cancels the
dialog.
Examples
Example 1
Example 1
// default usage
import { progress } from "@ayonli/jsext/dialog";
const result = await progress("Processing...", async () => {
// ... some long-running task
return { ok: true };
});
console.log(result); // { ok: true }
Example 2
Example 2
// update state
import { progress } from "@ayonli/jsext/dialog";
const result = await progress("Processing...", async (set) => {
set({ percent: 0 });
// ... some long-running task
set({ percent: 50, message: "Halfway there!" });
// ... some long-running task
set({ percent: 100 });
return { ok: true };
});
console.log(result); // { ok: true }
Example 3
Example 3
// abortable
import { progress } from "@ayonli/jsext/dialog";
const result = await progress("Processing...", async (set, signal) => {
set({ percent: 0 });
if (!signal.aborted) {
// ... some long-running task
set({ percent: 50, message: "Halfway there!" });
}
if (!signal.aborted) {
// ... some long-running task
set({ percent: 100 });
}
return { ok: true };
}, () => {
return { ok: false };
});
console.log(result); // { ok: true } or { ok: false }