chore(docs): cancel upcoming tasks if stopped
This commit is contained in:
@@ -60,6 +60,8 @@ const sourceNodeData = toRef(() => nodesData.value[1])
|
|||||||
|
|
||||||
const isFinished = toRef(() => sourceNodeData.value.isFinished)
|
const isFinished = toRef(() => sourceNodeData.value.isFinished)
|
||||||
|
|
||||||
|
const isCancelled = toRef(() => targetNodeData.value.isCancelled)
|
||||||
|
|
||||||
const isAnimating = ref(false)
|
const isAnimating = ref(false)
|
||||||
|
|
||||||
const edgeColor = toRef(() => {
|
const edgeColor = toRef(() => {
|
||||||
@@ -84,6 +86,12 @@ const edgeColor = toRef(() => {
|
|||||||
|
|
||||||
const path = computed(() => getSmoothStepPath(props))
|
const path = computed(() => getSmoothStepPath(props))
|
||||||
|
|
||||||
|
watch(isCancelled, (isCancelled) => {
|
||||||
|
if (isCancelled) {
|
||||||
|
isAnimating.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
watch(isAnimating, (isAnimating) => {
|
watch(isAnimating, (isAnimating) => {
|
||||||
const edge = findEdge(props.id)
|
const edge = findEdge(props.id)
|
||||||
|
|
||||||
@@ -98,7 +106,7 @@ watch(isAnimating, (isAnimating) => {
|
|||||||
watch(edgePoint, (point) => {
|
watch(edgePoint, (point) => {
|
||||||
const pathEl = edgeRef.value?.pathEl
|
const pathEl = edgeRef.value?.pathEl
|
||||||
|
|
||||||
if (!pathEl || point === 0) {
|
if (!pathEl || point === 0 || !isAnimating.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,18 +15,26 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
const graph = toRef(() => toValue(dagreGraph))
|
const graph = toRef(() => toValue(dagreGraph))
|
||||||
|
|
||||||
const isRunning = ref(false)
|
const isRunning = ref(false)
|
||||||
|
|
||||||
const executedNodes = new Set()
|
const executedNodes = new Set()
|
||||||
|
|
||||||
const runningTasks = new Map()
|
const runningTasks = new Map()
|
||||||
|
|
||||||
|
const upcomingTasks = new Set()
|
||||||
|
|
||||||
async function runNode(node, isStart = false) {
|
async function runNode(node, isStart = false) {
|
||||||
if (executedNodes.has(node.id)) {
|
if (executedNodes.has(node.id)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upcomingTasks.add(node.id)
|
||||||
|
|
||||||
const incomers = getConnectedEdges(node.id).filter((connection) => connection.target === node.id)
|
const incomers = getConnectedEdges(node.id).filter((connection) => connection.target === node.id)
|
||||||
|
|
||||||
await Promise.all(incomers.map((incomer) => until(() => !incomer.data.isAnimating)))
|
await Promise.all(incomers.map((incomer) => until(() => !incomer.data.isAnimating)))
|
||||||
|
|
||||||
|
upcomingTasks.clear()
|
||||||
|
|
||||||
if (!isRunning.value) {
|
if (!isRunning.value) {
|
||||||
// The process was stopped
|
// The process was stopped
|
||||||
return
|
return
|
||||||
@@ -114,6 +122,13 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
function stop() {
|
function stop() {
|
||||||
isRunning.value = false
|
isRunning.value = false
|
||||||
|
|
||||||
|
for (const nodeId of upcomingTasks) {
|
||||||
|
clearTimeout(runningTasks.get(nodeId))
|
||||||
|
runningTasks.delete(nodeId)
|
||||||
|
updateNodeData(nodeId, { isRunning: false, isFinished: false, hasError: false, isSkipped: false, isCancelled: true })
|
||||||
|
skipDescendants(nodeId)
|
||||||
|
}
|
||||||
|
|
||||||
for (const [nodeId, task] of runningTasks) {
|
for (const [nodeId, task] of runningTasks) {
|
||||||
clearTimeout(task)
|
clearTimeout(task)
|
||||||
runningTasks.delete(nodeId)
|
runningTasks.delete(nodeId)
|
||||||
@@ -122,6 +137,7 @@ export function useRunProcess({ dagreGraph, cancelOnError = true }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executedNodes.clear()
|
executedNodes.clear()
|
||||||
|
upcomingTasks.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
|
|||||||
Reference in New Issue
Block a user