Closed stevefan1999-personal closed 1 year ago
The problem is that the function write_all
returns a future which has a lifetime of 'js
, because it has taken TypedArray<'js, u8>
as an argument. The current implementation requires that async callbacks to return futures which are valid for the entire lifetime of 'static
.
I will look into the possibility of lifting this restriction but for now it is impossible to implement that method as an async function.
You could try to implement it as a normal function which returns a future which is valid for 'static
by making sure that TypedArray
is not passed into the future.
Something like:
pub fn write_all<'js>(self, buf: TypedArray<'js, u8>) -> impl Future<Output = rquickjs::Result<()>> {
// Move the data out of TypedArray
let buf: Vec<u8> = buf.as_ref().to_owned();
async move {
self.0.lock().await.write_all(&buf).await?;
Ok(())
}
}
Closing this issue as the problem is resolved and now also easily possible with the new version of the library
I watn to implement write_all:
However it seems like it is not acceptable?