Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support async calls for the rust crate #30

Merged
merged 4 commits into from
Apr 4, 2022

Conversation

itegulov
Copy link
Contributor

Fixes #29

Decided to move sync functions to a separate module and expose async ones by default since this seems to be a common practice in Rust crates. Also, because you can't create a module named async :)

@itegulov itegulov requested a review from ChaoticTempest March 18, 2022 11:12
crate/src/lib.rs Outdated
Comment on lines 61 to 64
let dl = dl_cache
.download(true, &tmp_dir, &["near-sandbox"], &bin_url())
.map_err(anyhow::Error::msg)?
.ok_or_else(|| anyhow!("Could not install near-sandbox"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The install function can potentially be swapped over to an async version as well, but a bit more involved since we'd have to replace binary_install and roll our own async version (no simple async download/install crate off the top of my head). This can be reserved for later, so no need to do it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a crack at this and I guess we could go with something like this: https://github.com/itegulov/binary-install-async. I used tokio just for the sake of simplicity, but I guess we would have to be async runtime agnostic, right?

To push it even further we can replace tar with async-tar. Unfortunately, the latter is tightly coupled with async-std so we would have to refactor that too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we would have to be async runtime agnostic, right?

yup, this is where it's going to be "fun". Since some of the fs operations does spawn blocking, we'll need to pass in a futures::task::Executor to make that part agnostic.

Generally, this comment pinpoints a good amount of details to make things runtime agnostic: rust-lang/wg-async#45 (comment). Let me know if you hit a snag though, since there could be dragons somewhere with async ecosystem being this fragmented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great source, thanks for sharing. I followed the suggestions and arrived at this: itegulov/binary-install-async@6522b50. Not sure what is the best way to give feedback, but feel free to leave comments directly under that commit.

Also, should we move the repo to NEAR org or is it fine to keep it as a personal repo for now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can just make it a workspace member crate of sandbox repo, or add it as helper functions. Whichever is easier.

feel free to leave comments directly under that commit

didn't know you could leave comments on commits to master, but will leave my feedback there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crate/src/lib.rs Outdated
Comment on lines 85 to 92
pub async fn run_with_options(options: &[&str]) -> anyhow::Result<Child> {
let bin_path = crate::ensure_sandbox_bin()?;
Command::new(bin_path)
.args(options)
.envs(log_vars())
.envs(crate::log_vars())
.spawn()
.map_err(Into::into)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize that spawn isn't async for async_process::Command. Looking at the code, it doesn't do anything different much from a regular std Command in this case, but the returned async_process::Child is still relevant for the asynchronous actions we can perform afterwards. So think its best to get rid of these async labels since we aren't doing any async work here. But if we were to make install async, then this function would then be async as well, so leaving this one up to you whether we should keep as async

Copy link
Contributor Author

@itegulov itegulov Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fair. Will do if we don't reach a conclusion on your first point short term and will handle the rest in a separate PR.

@itegulov itegulov requested a review from ChaoticTempest March 30, 2022 03:57
@itegulov
Copy link
Contributor Author

I have removed async modifiers from this PR and created an issue for the remaining work: #32

@ChaoticTempest ChaoticTempest merged commit c6688f1 into main Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

async support for the rust crate
2 participants