[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
This commit is contained in:
Sarah Allen 2020-01-22 07:32:47 -08:00 committed by Alex Crichton
parent 2b0a4178bf
commit ae6f4a9c87
2 changed files with 5 additions and 3 deletions

View File

@ -2,7 +2,7 @@ const rust = import('./pkg');
rust rust
.then(m => { .then(m => {
return m.run().then((data) => { return m.run("rustwasm/wasm-bindgen").then((data) => {
console.log(data); console.log(data);
console.log("The latest commit to the wasm-bindgen %s branch is:", data.name); console.log("The latest commit to the wasm-bindgen %s branch is:", data.name);

View File

@ -33,13 +33,15 @@ pub struct Signature {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub async fn run() -> Result<JsValue, JsValue> { pub async fn run(repo: String) -> Result<JsValue, JsValue> {
let mut opts = RequestInit::new(); let mut opts = RequestInit::new();
opts.method("GET"); opts.method("GET");
opts.mode(RequestMode::Cors); opts.mode(RequestMode::Cors);
let url = format!("https://api.github.com/repos/{}/branches/master", repo);
let request = Request::new_with_str_and_init( let request = Request::new_with_str_and_init(
"https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master", &url,
&opts, &opts,
)?; )?;