1 stable release

3.0.0 Feb 10, 2021

#18 in #vec-u8

Download history 383/week @ 2024-05-22 433/week @ 2024-05-29 338/week @ 2024-06-05 292/week @ 2024-06-12 314/week @ 2024-06-19 328/week @ 2024-06-26 27/week @ 2024-07-03 341/week @ 2024-07-10 371/week @ 2024-07-17 387/week @ 2024-07-24 329/week @ 2024-07-31 459/week @ 2024-08-07 429/week @ 2024-08-14 362/week @ 2024-08-21 356/week @ 2024-08-28 303/week @ 2024-09-04

1,546 downloads per month

Apache-2.0

16KB
296 lines

Runtime asynchronous, pure computational tasks.

License: Apache-2.0


lib.rs:

Runtime tasks.

Contains runtime-usable functions for spawning parallel purely computational tasks.

NOTE: This is experimental API. NOTE: When using in actual runtime, make sure you don't produce unbounded parallelism. So this is bad example to use it:

   fn my_parallel_computator(data: Vec<u8>) -> Vec<u8> {
       unimplemented!()
   }
   fn test(dynamic_variable: i32) {
       for _ in 0..dynamic_variable { sp_tasks::spawn(my_parallel_computator, vec![]); }
   }

While this is a good example:

   use codec::Encode;
   static STATIC_VARIABLE: i32 = 4;

   fn my_parallel_computator(data: Vec<u8>) -> Vec<u8> {
       unimplemented!()
   }

   fn test(computation_payload: Vec<u8>) {
       let parallel_tasks = (0..STATIC_VARIABLE).map(|idx|
           sp_tasks::spawn(my_parallel_computator, computation_payload.chunks(10).nth(idx as _).encode())
       );
   }

When allowing unbounded parallelism, malicious transactions can exploit it and partition network consensus based on how much resources nodes have.

Dependencies

~5–14MB
~190K SLoC