I am currently trying to build an asynchronous server with a database connection (Google Firestore). I am using the actix-web framework to do the HTTP routing etc., which uses a tokio executor under the hood.
As far as my understanding goes, each incoming HTTP request is delegated to a request handler function, which then returns a future, which is then polled by the underlying tokio executor, finally resolving it to a HTTP response.
My current task is to make the database queries asynchronous. There is a function in the firestore1 API, which executes a query and returns the query's results in a
Result. However, this function is currently blocking, and I would appreciate some help with figuring out how to implement a future which will check whether the function has finished yet or not.
I thought of calling the blocking function on a seperate thread and letting it put the result in a
Box<Option<T>>, so that the future could check the box if there was
Some(T) in it, otherwise return
Poll::Pending. However this would be inefficient, since the handler itself is already a tokio task issued by actix, and issuing another task inside that task seems redundant.
What would be the appropriate way to create a future for a long running function, which I can not modify?