Ensure devicePool.release is called for both providers even if one rejects
Just want to double check this code is doing what's expected.
https://github.com/gpuweb/cts/blob/ade41b29ef2be93d160a141d53069e43969ff3cf/src/webgpu/gpu_test.ts#L164
// Ensure devicePool.release is called for both providers even if one rejects.
await Promise.all([
this.provider?.then(x => devicePool.release(x)),
this.mismatchedProvider?.then(x => mismatchedDevicePool.release(x)),
]);
It will call devicePool.release on both. It will not wait before proceeding as Promise.all continues as soon as one promise rejects.
Is that fine that it doesn't wait? If we want it to wait then I think you'd need something like
// Ensure devicePool.release is called for both providers even if one rejects.
const results = await Promise.allSettled([
this.provider?.then(x => devicePool.release(x)),
this.mismatchedProvider?.then(x => mismatchedDevicePool.release(x)),
]);
const rejected = results.find(result => result.status === 'rejected');
if (rejected) {
throw rejected.reason;
}
@kainino0x
Just to be clear, this doesn't fix the dawn.node issue. I was just in this area of the code, saw that comment, wasn't sure the code was doing what I interpreted the comment to mean, and started playing around. Even with this change, dawn.node still gets the same errors.
// Ensure devicePool.release is called for both providers even if one rejects.
I think what this comment was saying is, make sure we call release on both of them. I.e. don't do:
await devicePool.release(x);
await mismatchedDevicePool.release(y);
However looking at what release() does, it would definitely be better to wait for both to settle (e.g. wait for x.lost even if something went wrong with y).
Your suggested code looks good to me.