Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add spawn and try_current for madsim-tokio #197

Merged
merged 8 commits into from
Apr 9, 2024
Merged

Conversation

KveinAxel
Copy link
Collaborator

to support madsim-rs/sqlx, we add some spawn, try_current and some other dummy interface.

Signed-off-by: Kevin Axel <kevinaxel@163.com>
Signed-off-by: Kevin Axel <kevinaxel@163.com>
Signed-off-by: Kevin Axel <kevinaxel@163.com>
Signed-off-by: Kevin Axel <kevinaxel@163.com>
Copy link
Member

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

Rest LGTM! Thanks

Comment on lines +48 to +50
pub fn try_read_buf<B: BufMut>(&mut self, buf: &mut B) -> io::Result<usize> {
unimplemented!();
}
Copy link
Member

Choose a reason for hiding this comment

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

Will this be implemented in the future? If so, we can use todo!().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This just used to pass the sqlx's compile, so maybe we can just leave a unimplemented here? So far sqlx hasn't called this on TcpStream yet.

F::Output: Send + 'static,
{
self.create_node()
.name("spawn a task")
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't create a new node here. The task should be spawned within the current node. Please use Spawner::current() instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have tried Spawner::current before, but in some cases, like dropping some Future and calling a sync drop to spawn an async task which means there are no tasks in the runtime. The drop site is out the scope of

let _guard = crate::context::enter_task(info.clone());

Copy link
Member

Choose a reason for hiding this comment

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

I see. In this case, I think we should enter task context before dropping the task. And here we should still use Spawner::current().

@wangrunji0408 wangrunji0408 enabled auto-merge (squash) April 9, 2024 08:56
@wangrunji0408 wangrunji0408 disabled auto-merge April 9, 2024 12:19
@wangrunji0408 wangrunji0408 enabled auto-merge (squash) April 9, 2024 12:20
@wangrunji0408 wangrunji0408 merged commit 91a8231 into main Apr 9, 2024
24 checks passed
@wangrunji0408 wangrunji0408 deleted the wff/sqlx branch April 9, 2024 12:33
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants