I’ve added various operators using Timers and now the package is published in mops.
Documentation: https://mops.one/rxmo/docs
Here is an example that illustrates the benefits of using RxMo.
Example 1:
You have a canister where users register and your function needs to run a few cross-canister calls for every user.
The problem is, you don’t really know how many users will try to register simultaneously, and if you
try to make 5 calls per user on registration with a canister that doesn’t have a lot of cycles, it will take ~10 simultaneous user registrations to reach the cycles limit, your calls will start to error which is a vulnerability that may lead to an exploit.
Example 2:
You are replicating a database and you want to group up your updates and send them to another canister without making too many concurrent requests.
Example 3:
You are creating transactions and sending them to your transaction history canister.
Solution:
The solution is to buffer all your calls and slowly get them thru. You can do that without RxMo. What RxMo does is provide you with tools that let you create something like a pipeline made out of helpful customizable operator functions.
Playground: https://m7sm4-2iaaa-aaaab-qabra-cai.ic0.app/?tag=3672190005
This example doesn’t look very pretty, but it works:
This creates your pipeline and once created, you can
main.next(Principal.fromText("mytki-xqaaa-aaaab-qabrq-cai"));
main.next(Principal.fromText("mytki-xqaaa-aaaab-qabrq-cai"));
That will send these principals into the pipeline, which later uses the operator bufferTime
to group them into arrays of 20 and pass one group ahead every 5 seconds. Then 20 calls in parallel are made and their results then send ahead.
The middle part doesn’t look very good, because I can’t get a library to work well with async generic types without getting non-shared content type error. https://forum.dfinity.org/t/motoko-sharable-generics/9021/ But I think we will figure this out sooner or later. Here is what a code doing the same thing would look like when we get that figured out.