options for the polling operation
either the result of the operation or an error if the operation times out. If results were returned, but the predicate was not met, a PredicateError is thrown. Otherwise, the failure is propagated as an error.
// Wait for a process instance to appear in the search results
const elementInstances = await PollingOperation({
operation: () =>
c8.searchElementInstances({
sort: [{ field: 'processInstanceKey' }],
filter: {
processInstanceKey: processInstance.processInstanceKey,
type: 'SERVICE_TASK',
},
}),
interval: 500,
timeout: 10000,
})
// If the operation does not return an object with an `items` array (ie: a v1 API), you need to provide a predicate function to check if the result is the awaited one.
const process = await PollingOperation({
operation: () => c.getProcessInstance(p.processInstanceKey),
predicate: (res) => res.key === p.processInstanceKey,
interval: 500,
timeout: 15000,
})
Poll for a result of an operation until it returns an awaited result or times out.
This is useful for operations that may take some time to complete, such as waiting for a process instance to finish or data to propagate to query indices.
Takes an optional prediicate function to determine if the result is the awaited one. By default, it checks if the result is not null or undefined and has at least one item in the items
array.
options for the polling operation
either the result of the operation or an error if the operation times out. If results were returned, but the predicate was not met, a PredicateError is thrown. Otherwise, the failure is propagated as an error.
// Wait for a process instance to appear in the search results
const elementInstances = await PollingOperation({
operation: () =>
c8.searchElementInstances({
sort: [{ field: 'processInstanceKey' }],
filter: {
processInstanceKey: processInstance.processInstanceKey,
type: 'SERVICE_TASK',
},
}),
interval: 500,
timeout: 10000,
})
// If the operation does not return an object with an `items` array (ie: a v1 API), you need to provide a predicate function to check if the result is the awaited one.
const process = await PollingOperation({
operation: () => c.getProcessInstance(p.processInstanceKey),
predicate: (res) => res.key === p.processInstanceKey,
interval: 500,
timeout: 15000,
})
Poll for a result of an operation until it returns an awaited result or times out. This is useful for operations that may take some time to complete, such as waiting for a process instance to finish or data to propagate to query indices. Takes an optional prediicate function to determine if the result is the awaited one. By default, it checks if the result is not null or undefined and has at least one item in the
items
array.