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


##########
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> {
+    let mut retry = opendal::layers::RetryLayer::default();
+
+    let config: Either<JsObject, JsUndefined> = ctx.try_get::<JsObject>(0)?;

Review Comment:
   > register those js function in rust
   
   What do you mean? I'm not sure about this part.



-- 
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