From ae6f4a9c8726c0a3c69b8597a1c4f667fc9f4d25 Mon Sep 17 00:00:00 2001 From: Sarah Allen Date: Wed, 22 Jan 2020 07:32:47 -0800 Subject: [PATCH] [WIP] add parameter to async function --> error (#1973) * add parameter to async function --> error This change to the fetch example does not compile. It would be great to include how to do this! * fn parameter as String --- examples/fetch/index.js | 2 +- examples/fetch/src/lib.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/fetch/index.js b/examples/fetch/index.js index c2d3d2ae..dbad2808 100644 --- a/examples/fetch/index.js +++ b/examples/fetch/index.js @@ -2,7 +2,7 @@ const rust = import('./pkg'); rust .then(m => { - return m.run().then((data) => { + return m.run("rustwasm/wasm-bindgen").then((data) => { console.log(data); console.log("The latest commit to the wasm-bindgen %s branch is:", data.name); diff --git a/examples/fetch/src/lib.rs b/examples/fetch/src/lib.rs index 3ef43ae7..d1dd7524 100644 --- a/examples/fetch/src/lib.rs +++ b/examples/fetch/src/lib.rs @@ -33,13 +33,15 @@ pub struct Signature { } #[wasm_bindgen] -pub async fn run() -> Result { +pub async fn run(repo: String) -> Result { let mut opts = RequestInit::new(); opts.method("GET"); opts.mode(RequestMode::Cors); + let url = format!("https://api.github.com/repos/{}/branches/master", repo); + let request = Request::new_with_str_and_init( - "https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master", + &url, &opts, )?;