-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Get source, screenshot and windowSize concurrently #916
Conversation
I've used |
@jlipps I need the promises to complete even if they don't resolve. I need either the result or the error for all 3 calls. |
Does it really work faster? base driver queues all commands by default, so they cannot run simultaneously |
Bluebird has .timeout for that |
@mykola-mokhnach in a cloud environment it definitely will: Currently, we do it sequentially which does this:
After this PR it will be:
tl:dr; in cloud environment, we don't have to wait for response to download before starting next request |
|
If you want to stay const a = new B((resolve, reject) => {
setTimeout(function () {
resolve('done with a');
}, 5000);
});
const b = new B((resolve, reject) => {
setTimeout(function () {
reject(new Error('problem with b'));
}, 4000);
});
const c = new B((resolve, reject) => {
setTimeout(function () {
resolve('done with c');
}, 3000);
});
const res = await B.all([a, b, c].map((p) => {
return p.reflect();
})).map((pi) => {
if (pi.isFulfilled()) {
return pi.value();
} else {
return pi.reason();
}
});
console.log('res:', res); The output of which would be:
|
Sitting around bored at home and came up with this: const source = new B((resolve, reject) => {
resolve('got source');
});
const screenshot = new B((resolve, reject) => {
reject(new Error('error getting screenshot'));
});
const windowSize = new B((resolve, reject) => {
resolve('got window size');
});
const names = ['source', 'screenshot', 'windowSize'];
const res = await B.all([source, screenshot, windowSize].map((p) => {
return p.reflect();
})).map((pi) => {
return pi.isFulfilled()
? [pi.value(), undefined]
: [undefined, pi.reason()];
}).reduce((acc, val, i) => {
acc[`${names[i]}`] = val[0];
acc[`${names[i]}Error`] = val[1];
return acc;
}, {});
console.log(res); Gets:
|
I just tried @imurchie 's way and it is throwing an exception.... Should I troubleshoot this some more and find a bluebird/promise way of doing this or is this okay how it is? |
What is the exception? |
[0] 15:23:14.275 › Retrieving session for window with id: 5
[0] Handling client method request with method 'source' and args []
[0] Caught an exception: TypeError: e.reflect is not a function
[0] at e.default.all.map.e (/Users/danielgraham/appium-desktop/dist/main.js:80:2854)
[0] at Array.map (<anonymous>)
[0] at u._getSourceAndScreenshot (/Users/danielgraham/appium-desktop/dist/main.js:80:2845)
[0] at u._execute (/Users/danielgraham/appium-desktop/dist/main.js:80:2380) |
Weird. Must not be a Bluebird promise. Anyway, more trouble than it's worth, I say. |
I believe this change is failing Perfecto cloud provider. Screenshot keeps spinning and source keeps loading. Let me know if you more information is needed. |
Can you get any logs launching from source? |
@vijayqaguy I think you're right. I'm seeing this on Sauce Labs too. May need to revert this. |
Promise.all
doesn't support waiting for all promises to resolve. I needed a solution that completes all three of the promises and then sends the result back.finally
to callcheckShouldResolve
, but there's a race condition that causesfinally
to sometimes be called beforethen
orcatch
.