Check for pending events before updating the config

Small optimisation that significantly reduces number of config updates.
This commit is contained in:
Ingvar Stepanyan
2021-07-23 20:04:32 +00:00
parent 86f9be758f
commit ca75f61289
2 changed files with 18 additions and 2 deletions

13
api.cpp
View File

@@ -60,6 +60,16 @@ class Context {
}); });
} }
bool hasPendingEvent() {
return gpp_rethrow([=]() {
CameraEventType event_type = GP_EVENT_UNKNOWN;
gpp_unique_ptr<void, free> event_data(GPP_CALL(
void *, gp_camera_wait_for_event(camera.get(), 0, &event_type, _,
context.get())));
return event_type != GP_EVENT_TIMEOUT;
});
}
val configToJS() { val configToJS() {
return gpp_rethrow([=]() { return gpp_rethrow([=]() {
GPPWidget config( GPPWidget config(
@@ -277,5 +287,6 @@ EMSCRIPTEN_BINDINGS(gphoto2_js_api) {
.function("configToJS", &Context::configToJS) .function("configToJS", &Context::configToJS)
.function("setConfigValue", &Context::setConfigValue) .function("setConfigValue", &Context::setConfigValue)
.function("capturePreviewAsBlob", &Context::capturePreviewAsBlob) .function("capturePreviewAsBlob", &Context::capturePreviewAsBlob)
.function("captureImageAsFile", &Context::captureImageAsFile); .function("captureImageAsFile", &Context::captureImageAsFile)
.function("hasPendingEvent", &Context::hasPendingEvent);
} }

View File

@@ -79,7 +79,12 @@ class App extends Component {
type: 'Config', type: 'Config',
config config
}); });
await new Promise(resolve => setTimeout(resolve, 100)); do {
await new Promise(resolve => setTimeout(resolve, 100));
} while (
!(await this.connection.schedule(context => context.hasPendingEvent()))
);
console.log('Event!');
} }
} }