Split out action polling to separate function.
This commit is contained in:
parent
2b0b548307
commit
cd30872d62
1 changed files with 25 additions and 8 deletions
|
|
@ -221,6 +221,19 @@ export default {
|
||||||
const snapshotUri = this.snapshotStreamUri;
|
const snapshotUri = this.snapshotStreamUri;
|
||||||
const captureActionUri = this.captureActionUri;
|
const captureActionUri = this.captureActionUri;
|
||||||
const modalError = this.modalError;
|
const modalError = this.modalError;
|
||||||
|
async function pollUntilComplete(response) {
|
||||||
|
// Poll an action until its status is completed
|
||||||
|
// TODO: raise an error if it fails or is cancelled
|
||||||
|
// For ease, this accepts and returns a response object from
|
||||||
|
// axios.get
|
||||||
|
// FIXME: this could be an infinite loop if the task is cancelled/errored
|
||||||
|
let r = response;
|
||||||
|
while (r.data.status != "completed") {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
|
r = await axios.get(r.data.href);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
const service = {
|
const service = {
|
||||||
type: "_microscope-control",
|
type: "_microscope-control",
|
||||||
name: "OpenFlexure",
|
name: "OpenFlexure",
|
||||||
|
|
@ -247,15 +260,11 @@ export default {
|
||||||
//.catch(modalError);
|
//.catch(modalError);
|
||||||
},
|
},
|
||||||
async getImage() {
|
async getImage() {
|
||||||
// FIXME: this could be an infinite loop if the task is cancelled/errored
|
|
||||||
// FIXME: handle nicely getImage() being called before snapImage()
|
// FIXME: handle nicely getImage() being called before snapImage()
|
||||||
while (service.lastSnapResponse.data.status != "completed") {
|
// Wait until the capture has completed and we can retrieve it
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
service.lastSnapResponse = await pollUntilComplete(
|
||||||
service.lastSnapResponse = await axios.get(
|
service.lastSnapResponse
|
||||||
service.lastSnapResponse.data.href
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
// TODO: better error handling for the task not completing
|
|
||||||
let capture = service.lastSnapResponse.data.output;
|
let capture = service.lastSnapResponse.data.output;
|
||||||
// TODO: check links.download.href exists and is JPEG
|
// TODO: check links.download.href exists and is JPEG
|
||||||
let jpeg = await axios
|
let jpeg = await axios
|
||||||
|
|
@ -274,10 +283,18 @@ export default {
|
||||||
return jpeg; //TODO: what is the expected output format???
|
return jpeg; //TODO: what is the expected output format???
|
||||||
},
|
},
|
||||||
setPosition() {
|
setPosition() {
|
||||||
|
// The C api suggests this defaults to just Z, and can accept a "label" to
|
||||||
|
// select the stage.
|
||||||
alert("Not implemented");
|
alert("Not implemented");
|
||||||
},
|
},
|
||||||
getPosition() {
|
getPosition() {
|
||||||
alert("Not implemented");
|
alert("Not implemented");
|
||||||
|
},
|
||||||
|
setXYPosition() {
|
||||||
|
alert("Not implemented");
|
||||||
|
},
|
||||||
|
getXYPosition() {
|
||||||
|
alert("Not implemented");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.imjoy.pm.registerService({ name: "openflexure" }, service);
|
this.imjoy.pm.registerService({ name: "openflexure" }, service);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue