Skip to content

Commit

Permalink
Added examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Oct 18, 2022
1 parent 3d666dc commit 512ee60
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/basic-fragile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::thread;

use fragile::Fragile;

fn main() {
// creating and using a fragile object in the same thread works
let val = Fragile::new(true);
println!("debug print in same thread: {:?}", &val);
println!("try_get in same thread: {:?}", val.try_get());

// once send to another thread it stops working
thread::spawn(move || {
println!("debug print in other thread: {:?}", &val);
println!("try_get in other thread: {:?}", val.try_get());
})
.join()
.unwrap();
}
21 changes: 21 additions & 0 deletions examples/basic-sticky.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::thread;

use fragile::Sticky;

fn main() {
fragile::stack_token!(tok);

// creating and using a fragile object in the same thread works
let val = Sticky::new(true);
println!("debug print in same thread: {:?}", &val);
println!("try_get in same thread: {:?}", val.try_get(tok));

// once send to another thread it stops working
thread::spawn(move || {
fragile::stack_token!(tok);
println!("debug print in other thread: {:?}", &val);
println!("try_get in other thread: {:?}", val.try_get(tok));
})
.join()
.unwrap();
}

0 comments on commit 512ee60

Please sign in to comment.