File size: 2,000 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
#![feature(arbitrary_self_types)]
#![feature(arbitrary_self_types_pointers)]
#![allow(clippy::needless_return)] // tokio macro-generated code doesn't respect this
use anyhow::Result;
use turbo_tasks::Vc;
use turbo_tasks_testing::{Registration, register, run};
static REGISTRATION: Registration = register!();
#[tokio::test]
async fn basic() {
run(®ISTRATION, || async {
let output1 = func_without_args();
assert_eq!(output1.await?.value, 123);
let input = Value { value: 42 }.cell();
let output2 = func_transient(input);
assert_eq!(output2.await?.value, 42);
let output3 = func_persistent(output1);
assert_eq!(output3.await?.value, 123);
let output4 = nested_func_without_args_waiting();
assert_eq!(output4.await?.value, 123);
let output5 = nested_func_without_args_non_waiting();
assert_eq!(output5.await?.value, 123);
anyhow::Ok(())
})
.await
.unwrap()
}
#[turbo_tasks::value]
#[derive(Clone, Debug)]
struct Value {
value: u32,
}
#[turbo_tasks::function]
async fn func_transient(input: Vc<Value>) -> Result<Vc<Value>> {
println!("func_transient");
let value = input.await?.value;
Ok(Value { value }.cell())
}
#[turbo_tasks::function]
async fn func_persistent(input: Vc<Value>) -> Result<Vc<Value>> {
println!("func_persistent");
let value = input.await?.value;
Ok(Value { value }.cell())
}
#[turbo_tasks::function]
fn func_without_args() -> Result<Vc<Value>> {
println!("func_without_args");
let value = 123;
Ok(Value { value }.cell())
}
#[turbo_tasks::function]
async fn nested_func_without_args_waiting() -> Result<Vc<Value>> {
println!("nested_func_without_args_waiting");
let value = func_without_args().owned().await?;
Ok(value.cell())
}
#[turbo_tasks::function]
fn nested_func_without_args_non_waiting() -> Result<Vc<Value>> {
println!("nested_func_without_args_non_waiting");
Ok(func_without_args())
}
|