Clean up; Add example
This commit is contained in:
parent
7dc7f7a351
commit
2da0a6a28b
@ -39,18 +39,14 @@ impl AbstractNode for AsyncBlock {
|
||||
}
|
||||
|
||||
fn evaluate(self, _context: &Context, _: bool) -> Result<Option<Evaluation>, RuntimeError> {
|
||||
let statement_count = self.statements.len();
|
||||
let final_result = Mutex::new(Ok(None));
|
||||
|
||||
self.statements
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.find_map_any(
|
||||
|(index, statement)| -> Option<Result<Option<Evaluation>, RuntimeError>> {
|
||||
let statement_count = self.statements.len();
|
||||
let error_option = self.statements.into_par_iter().enumerate().find_map_any(
|
||||
|(index, statement)| -> Option<RuntimeError> {
|
||||
let result = statement.evaluate(&_context, false);
|
||||
|
||||
if result.is_err() {
|
||||
return Some(result);
|
||||
if let Err(error) = result {
|
||||
return Some(error);
|
||||
}
|
||||
|
||||
if index == statement_count - 1 {
|
||||
@ -60,8 +56,13 @@ impl AbstractNode for AsyncBlock {
|
||||
|
||||
None
|
||||
},
|
||||
)
|
||||
.unwrap_or(final_result.into_inner()?)
|
||||
);
|
||||
|
||||
if let Some(error) = error_option {
|
||||
Err(error)
|
||||
} else {
|
||||
final_result.into_inner()?
|
||||
}
|
||||
}
|
||||
|
||||
fn expected_type(&self, _context: &Context) -> Result<Option<Type>, ValidationError> {
|
||||
|
19
examples/async_count.ds
Normal file
19
examples/async_count.ds
Normal file
@ -0,0 +1,19 @@
|
||||
count_slowly = fn (multiplier: int) {
|
||||
i = 0
|
||||
|
||||
while i < 10 {
|
||||
sleep_time = i * multiplier;
|
||||
|
||||
thread.sleep(sleep_time)
|
||||
io.write_line(i as str)
|
||||
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
async {
|
||||
count_slowly(50)
|
||||
count_slowly(100)
|
||||
count_slowly(200)
|
||||
count_slowly(250)
|
||||
}
|
Loading…
Reference in New Issue
Block a user