Skip to content

use async scope instead of unchecked borrow#10

Open
ant32 wants to merge 1 commit into
danog:masterfrom
ant32:async-scope
Open

use async scope instead of unchecked borrow#10
ant32 wants to merge 1 commit into
danog:masterfrom
ant32:async-scope

Conversation

@ant32
Copy link
Copy Markdown
Contributor

@ant32 ant32 commented Mar 21, 2026

simplify the code and library usage by copying the idea from https://crates.io/crates/async-scoped

this is a breaking change in that this now needs to be replaced with self as in the following example.

#[php_class]
struct Client {
    client: reqwest::Client,
}

#[php_async_impl]
impl Client {
    pub fn init() -> PhpResult<u64> {
        EventLoop::init()
    }
    pub fn wakeup() -> PhpResult<()> {
        EventLoop::wakeup()
    }
    pub fn new() -> Self {
        let client = reqwest::ClientBuilder::new().build().unwrap();
        Self {client}
    }
    pub async fn get(&mut self, url: &str) -> anyhow::Result<String> {
        Ok(self.client.get(url).send().await?.text().await?)
    }
}

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.

1 participant