Updated Timer Tool For Motoko

We have updated the timerTool to core in v0.2.0!

Features

  • Schedule timer events with custom parameters

  • Synchronous and asynchronous action support

  • Automatic timer reconstitution after upgrades

  • Safety timers for trap recovery

  • Automatic initialization via ClassPlus

The new Repo is at: GitHub - icdevsorg/timerTool: manage and recover timers in motoko

or mops add timer-tool

The most interesting new feature is mix-in support:

import TT “mo:timer-tool”;
import TTMixin “mo:timer-tool/TimerToolMixin”;
import ClassPlus “mo:class-plus”;
import Principal “mo:core/Principal”;
import Star “mo:star/star”;

shared ({ caller = \_owner }) persistent actor class MyCanister() = this {

transient let canisterId = Principal.fromActor(this);
transient let classPlus = ClassPlus.ClassPlusInitializationManager(\_owner, canisterId, true);

// Include the TimerTool mixin
include TTMixin({
  config = {
    org_icdevs_class_plus_manager = classPlus;
    args = null;
    pullEnvironment = ?(func() : TT.Environment {
      {
        advanced = null;
        syncUnsafe = null;
        reportExecution = null;
        reportError = null;
        reportBatch = null;
      };
    });
    onInitialize = ?(func(tt: TT.TimerTool) : async\* () {
        // Register your handlers here
        tt.registerExecutionListenerSync(?“myTask”, handleMyTask);
      });
    };
    caller = \_owner;
    canisterId = canisterId;
  });

  // Your handler
  private func handleMyTask(id: TT.ActionId, action: TT.Action) : TT.ActionId {
    // Decode params and process
    let ?data : ?Nat = from_candid(action.params) else return id;
    // Do work…
    id;
  };

  // Schedule a task
  public shared func scheduleTask(executeAt: Nat, data: Nat) : async Nat {
    let actionId = org_icdevs_timer_tool.setActionSync(executeAt, {
      actionType = “myTask”;
      params = to_candid(data);
    });
    actionId.id;
   };
  };

See more at the repo. Fork, contribute, and send pull requests.

2 Likes

@skilesare who is this new account ? The Initial Release was one week ago.

Finally, Motoko malware.

1 Like

Just setting up a separate ICDevs account…no malware. :smiley:

Clearly the markdown is screwed though. I’ll fix it when the discourse gives me more rights.

Ok thanks for the heads up :wink:

do you have enough rights now? I increased the trust level of the account

2 Likes

You jest but I had this crazy idea for a canister with a small neuron and when it gets enough maturity it mints another canister w a small neuron and so on and so forth, like a fractal of compounding and self populating canisters. Would be like a horse, it doesn’t stop it keeps going.

It would be set up to pay its own cycles and then as maturity compounds top itself off etc. I have some napkin math on how it would work. And like, it has to no purpose etc but like imagine if it just kept going and over the years just kept making new canisters. It would go viral!

All fixed! Thank you.

1 Like