mirror of
https://github.com/facebook/sapling.git
synced 2024-12-26 06:21:48 +03:00
pyedenapi: switch to async_runtime::block_on_future
Summary: This simplifies the code a bit, and avoids creating tokio Runtime multiple times. Reviewed By: kulshrax Differential Revision: D23799642 fbshipit-source-id: 21cee6124ef6f9ab6e165891d9ee87b2feb553ac
This commit is contained in:
parent
186151e8f9
commit
ebf708e17a
@ -5,6 +5,7 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
async-runtime = { path = "../../../../lib/async-runtime" }
|
||||
bytes = "0.5"
|
||||
cpython-async = { path = "../../../../lib/cpython-async", default-features = false }
|
||||
cpython-ext = { path = "../../../../lib/cpython-ext", default-features = false }
|
||||
@ -15,7 +16,6 @@ futures = { version = "0.3.5", features = ["async-await", "compat"] }
|
||||
pyconfigparser = { path = "../pyconfigparser" }
|
||||
pyrevisionstore = { path = "../pyrevisionstore" }
|
||||
revisionstore = { path = "../../../../lib/revisionstore" }
|
||||
tokio = { version = "=0.2.13", features = ["full"] }
|
||||
types = { path = "../../../../lib/types" }
|
||||
|
||||
[features]
|
||||
|
@ -7,11 +7,10 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Context;
|
||||
use cpython::*;
|
||||
use futures::prelude::*;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use async_runtime::block_on_future;
|
||||
use cpython_async::PyFuture;
|
||||
use cpython_async::TStream;
|
||||
use cpython_ext::{PyPathBuf, ResultPyErrExt};
|
||||
@ -51,8 +50,7 @@ pub trait EdenApiPyExt: EdenApi {
|
||||
|
||||
let stats = py
|
||||
.allow_threads(|| {
|
||||
let mut rt = Runtime::new().context("Failed to initialize Tokio runtime")?;
|
||||
rt.block_on(async move {
|
||||
block_on_future(async move {
|
||||
let response = self.files(repo, keys, progress).await?;
|
||||
write_file(response, store).await
|
||||
})
|
||||
@ -77,8 +75,7 @@ pub trait EdenApiPyExt: EdenApi {
|
||||
|
||||
let stats = py
|
||||
.allow_threads(|| {
|
||||
let mut rt = Runtime::new().context("Failed to initialize Tokio runtime")?;
|
||||
rt.block_on(async move {
|
||||
block_on_future(async move {
|
||||
let response = self.history(repo, keys, length, progress).await?;
|
||||
write_history(response, store).await
|
||||
})
|
||||
@ -102,8 +99,7 @@ pub trait EdenApiPyExt: EdenApi {
|
||||
|
||||
let stats = py
|
||||
.allow_threads(|| {
|
||||
let mut rt = Runtime::new().context("Failed to initialize Tokio runtime")?;
|
||||
rt.block_on(async move {
|
||||
block_on_future(async move {
|
||||
let response = self.trees(repo, keys, progress).await?;
|
||||
write_tree(response, store).await
|
||||
})
|
||||
@ -132,8 +128,7 @@ pub trait EdenApiPyExt: EdenApi {
|
||||
|
||||
let stats = py
|
||||
.allow_threads(|| {
|
||||
let mut rt = Runtime::new().context("Failed to initialize Tokio runtime")?;
|
||||
rt.block_on(async move {
|
||||
block_on_future(async move {
|
||||
let response = self
|
||||
.complete_trees(repo, rootdir, mfnodes, basemfnodes, depth, progress)
|
||||
.await?;
|
||||
@ -157,8 +152,7 @@ pub trait EdenApiPyExt: EdenApi {
|
||||
|
||||
let (commits, stats) = py
|
||||
.allow_threads(|| {
|
||||
let mut rt = Runtime::new().context("Failed to initialize Tokio runtime")?;
|
||||
rt.block_on(async move {
|
||||
block_on_future(async move {
|
||||
let response = self.commit_revlog_data(repo, nodes, progress).await?;
|
||||
let commits = response.entries;
|
||||
let stats = response.stats;
|
||||
|
Loading…
Reference in New Issue
Block a user