Skip to content

Commit ae6f4a9

Browse files
ultrasaurusalexcrichton
authored andcommitted
[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
1 parent 2b0a417 commit ae6f4a9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

examples/fetch/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const rust = import('./pkg');
22

33
rust
44
.then(m => {
5-
return m.run().then((data) => {
5+
return m.run("rustwasm/wasm-bindgen").then((data) => {
66
console.log(data);
77

88
console.log("The latest commit to the wasm-bindgen %s branch is:", data.name);

examples/fetch/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ pub struct Signature {
3333
}
3434

3535
#[wasm_bindgen]
36-
pub async fn run() -> Result<JsValue, JsValue> {
36+
pub async fn run(repo: String) -> Result<JsValue, JsValue> {
3737
let mut opts = RequestInit::new();
3838
opts.method("GET");
3939
opts.mode(RequestMode::Cors);
4040

41+
let url = format!("https://api.github.com/repos/{}/branches/master", repo);
42+
4143
let request = Request::new_with_str_and_init(
42-
"https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master",
44+
&url,
4345
&opts,
4446
)?;
4547

0 commit comments

Comments
 (0)