bokket commented on PR #3763:
URL: 
https://github.com/apache/incubator-opendal/pull/3763#issuecomment-1859249449

   > I'm not clear on this. Could you provide a code sample to illustrate your 
idea?
   
   ```rust
   pub struct HdfsWriter<F> {
       target_path: String,
       tmp_path: Option<String>,
       client: Arc<hdrs::Client>,
   
       size:usize,
   
   
       f: F,
       fut: Option<BoxFuture<'static, Result<()>>>,
   }
   
   impl<F> HdfsWriter<F> {
       pub fn new(target_path: String, tmp_path: Option<String>,client: 
Arc<hdrs::Client>,f:F) -> Self {
           Self {
   
               target_path,
               tmp_path,
               client,
   
               size:0,
               f,
               fut:None,
           }
       }
   }
   
   unsafe impl<F> Sync for HdfsWriter<F> {}
   #[async_trait]
   impl oio::Write for HdfsWriter<hdrs::AsyncFile> {
       fn poll_write(&mut self, cx: &mut Context<'_>, bs: &dyn oio::WriteBuf) 
-> Poll<Result<usize>> {
           //Pin::new(&mut self.f)
           //let f = self.f.as_mut().expect("FsWriter must be initialized");
           self.size = bs.remaining();
           Pin::new(&mut self.f)
               .poll_write(cx, bs.chunk())
               .map_err(new_std_io_error)
       }
   
       async fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>> 
{
           loop {
               if let Some(fut) = self.fut.as_mut() {
                   let res = ready!(fut.poll_unpin(cx));
                   self.fut = None;
                   return Poll::Ready(res);
               }
   
   
   
               let mut f = self.f.take(self.size).expect("FsWriter must be 
initialized");
               let tmp_path = self.tmp_path.clone();
               let target_path = self.target_path.clone();
               self.fut = Some(Box::pin(async move {
                 f.poll_close(cx).await.map_err(new_std_io_error)?;
   
                   if let Some(tmp_path) = &tmp_path {
                       self.client
                           .rename_file(tmp_path, &target_path)
                           .map_err(new_std_io_error)?;
                   }
                   Ok(())
               }));
           }
       }
   }
   ```
   I need some helps......Compiler mainly thinked that the `poll_close` method 
of `<AsyncFile> is not `async` and cannot use `await` to wait for other threads 
to complete it, because the competitive relationship will cause memory access 
errors.


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