Skip to content

Using Task Status

Sometimes you need to know Task statuses. For example, you might want to show a fallback UI if core functionality fails.

Each Task exposes a .status property that returns its current status: done, skip, or fail.

import { status } from "@grlt-hub/app-compose"
const controlTask = createTask({
name: "control",
run: {
// Pass task statuses via context
context: [fetchUser.status],
fn: (ctx) => {
/* Logic to handle checks */
},
},
})

Check out this interactive example to see task.status in action:

import { compose, createTask } from "@grlt-hub/app-compose"
const fetchUser = createTask({
name: "fetch-user",
run: {
fn: () => {
// 👇 Uncomment to simulate failure
// throw new Error("[fetch-user]: failed")
},
},
})
const controlTask = createTask({
name: "control",
run: {
// 👇 Pass task statuses via context
context: [fetchUser.status],
fn: (ctx) => {
const failure = ctx.some((status) => status === "fail")
if (failure) {
console.log("Something went wrong. Please try again.")
} else {
console.log("Everything is working!")
}
},
},
})
compose()
.stage({ steps: [fetchUser] })
.stage({ steps: [controlTask] })
.run()