suyanhanx commented on code in PR #3484:
URL: 
https://github.com/apache/incubator-opendal/pull/3484#discussion_r1387775556


##########
bindings/nodejs/src/lib.rs:
##########
@@ -686,6 +691,117 @@ impl PresignedRequest {
     }
 }
 
+pub trait NodeLayer: Send + Sync {
+    fn layer(&self, op: opendal::Operator) -> opendal::Operator;
+}
+
+struct NodeLayerWrapper {
+    inner: Box<dyn NodeLayer>,
+}
+
+#[napi]
+impl Operator {
+    /// Add a layer to this operator.
+    #[napi]
+    pub fn layer(&self, env: Env, layer: JsObject) -> Result<Self> {
+        let ctx: &mut NodeLayerWrapper = env
+            .unwrap(&layer)
+            .map_err(|e| Error::from_reason(format!("failed to unwrap layer: 
{}", e)))?;
+        Ok(Self(ctx.inner.layer(self.0.clone())))
+    }
+}
+
+/// A layer that will retry the request if it fails.
+/// It will retry with exponential backoff.
+///
+/// ## Parameters
+///
+/// - `jitter`<bool>: Whether to add jitter to the backoff.
+/// - `max_times`<number>: The maximum number of times to retry.
+/// - `factor`<number>: The exponential factor to use.
+/// - `max_delay`<number>: The maximum delay between retries. The unit is 
microsecond.
+/// - `min_delay`<number>: The minimum delay between retries. The unit is 
microsecond.
+#[napi]
+pub struct RetryLayer(opendal::layers::RetryLayer);
+
+impl NodeLayer for RetryLayer {
+    fn layer(&self, op: opendal::Operator) -> opendal::Operator {
+        op.layer(self.0.clone())
+    }
+}
+
+/// RetryLayer constructor.
+#[js_function(1)]
+pub fn create_retry_layer(ctx: CallContext) -> Result<JsObject> {

Review Comment:
   IMO, no. I considered that every parameter is optional, and we need to deal 
with those unprovided parameters silently, but this get method will raise an 
error when trying to get an undefined property, I had to deal with those error 
cases one by one.
   Do you have any suggestions?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to