1 stable release

3.0.0 Feb 10, 2021

#18 in #vec-u8

Download history 159/week @ 2024-11-17 317/week @ 2024-11-24 344/week @ 2024-12-01 476/week @ 2024-12-08 551/week @ 2024-12-15 159/week @ 2024-12-22 96/week @ 2024-12-29 466/week @ 2025-01-05 752/week @ 2025-01-12 616/week @ 2025-01-19 219/week @ 2025-01-26 527/week @ 2025-02-02 627/week @ 2025-02-09 272/week @ 2025-02-16 604/week @ 2025-02-23 210/week @ 2025-03-02

1,814 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

~4–14MB
~180K SLoC