-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime_example): add example of hot reloading in the Mun Runtime
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use mun_runtime::{invoke_fn, RetryResultExt, RuntimeBuilder}; | ||
use std::env; | ||
|
||
// How to run? | ||
// 1. On the CLI, navigate to the `crates/mun_runtime/examples` directory. | ||
// 2. Run the compiler daemon from the CLI: `/path/to/mun build resources/fibonacci.mun --watch` | ||
// 3. Run the application from the CLI: cargo run --example hot_reloading -- fibonacci.dll | ||
fn main() { | ||
let lib_dir = env::args().nth(1).expect("Expected path to a Mun library."); | ||
println!("lib: {}", lib_dir); | ||
|
||
let mut runtime = RuntimeBuilder::new(lib_dir) | ||
.spawn() | ||
.expect("Failed to spawn Runtime"); | ||
|
||
loop { | ||
let n: i64 = invoke_fn!(runtime, "nth").wait(); | ||
let result: i64 = invoke_fn!(runtime, "fibonacci", n).wait(); | ||
println!("fibonacci({}) = {}", n, result); | ||
runtime.update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn nth(): int { | ||
3 | ||
} | ||
|
||
fn fibonacci(n:int):int { | ||
if n <= 1 { | ||
n | ||
} else { | ||
fibonacci(n-1) + fibonacci(n-2) | ||
} | ||
} |