Error handling for promise returning operations

This commit is contained in:
Kunal Mohan 2020-08-02 12:45:22 +05:30
parent 8cb5fad828
commit cd8d9162e6
5 changed files with 93 additions and 55 deletions

View file

@ -20,7 +20,7 @@ use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use std::ptr::NonNull;
use std::rc::Rc;
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse};
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
#[dom_struct]
pub struct GPUAdapter {
@ -114,14 +114,14 @@ impl GPUAdapterMethods for GPUAdapter {
}
impl AsyncWGPUListener for GPUAdapter {
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
match response {
WebGPUResponse::RequestDevice {
Ok(WebGPUResponse::RequestDevice {
device_id,
queue_id,
_descriptor,
label,
} => {
}) => {
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
@ -135,7 +135,14 @@ impl AsyncWGPUListener for GPUAdapter {
self.global().add_gpu_device(&device);
promise.resolve_native(&device);
},
_ => promise.reject_error(Error::Operation),
Err(e) => {
warn!("Could not get GPUDevice({:?})", e);
promise.reject_error(Error::Operation);
},
_ => {
warn!("GPUAdapter received wrong WebGPUResponse");
promise.reject_error(Error::Operation);
},
}
}
}