This library defines the response object used by the QVAC API. All responses from QVAC actions—such as inference, training, etc.—are returned as an instance of QvacResponse. The class now supports not only output streaming and cancellation, but also pausing and resuming the linked execution process. It also provides a chainable finish hook with a separate await() method to retrieve the final outputs.
npm i @qvac/response
When instantiating a QvacResponse, you must supply handler functions for canceling, pausing, and continuing the underlying process. For example:
const QvacResponse = require('@qvac/response')
const response = new QvacResponse({
cancelHandler: async () => {
// Logic to cancel the process
},
pauseHandler: async () => {
// Logic to pause the process
},
continueHandler: async () => {
// Logic to continue the process after a pause
}
},
100 // pollInterval nterval 100 by default
)
You can consume the output updates as they arrive using the async iterator:
for await (const output of response.iterate()) {
console.log('Received update:', output)
}
Or, you can register a callback to be notified of each update:
response.onUpdate((output) => {
console.log('Update:', output)
})
The finish hook is now chainable via onFinish().
You can await for the response to finish and retrieve the final outputs by calling the await() method. For example:
response
.onFinish((finalOutputs) => {
console.log('Final outputs via onFinish callback:', finalOutputs)
})
.onUpdate((output) => {
console.log('Intermediate update:', output)
})
(...)
//You can chain the await() method or later in your code await the promise to finish:
await response.await()
Or directly await the method and get the final response
const finalOutputs = response.await()
console.log('Final outputs via await():', finalOutputs)
To cancel the linked execution process:
response.cancel()
You can pause the execution process and later continue it:
// To pause:
await response.pause()
console.log('Response paused:', response.getStatus())
// To continue:
await response.continue()
console.log('Response resumed:', response.getStatus())
You can always check the current status of the response:
console.log('Current status:', response.getStatus())
// Possible statuses include: 'running', 'paused', 'ended', 'errored', 'cancelled'