Skip to main content
Back

Motoko update January 16, 2023

by Kento Sugama

Header image

Hey Motoko devs,

Happy New Year!

The languages team is back in 2023, hitting the ground running and picking up right where we left off last year. Before we move on, if you missed our last joint post with the SDK team, check it out here. As a recap, the languages team left off last year by focusing on testing and documenting large portions of the Motoko base library.

New language feature: Motoko timers

Header image

Meet Motoko timers! This is a new language feature that allows you to easily access the timers capability of the internet computer that lets you schedule asynchronous jobs for the future!

The most straightforward way to access this feature is through the Timer.mo base library, which exposes setTimer and recurringTimer.

setTimer : (d : Duration, job : () -> async ()) -> (id : Nat)
recurringTimer : (d : Duration, job : () -> async ()) -> (id : Nat)
cancelTimer : (id : Nat) -> ()

Use setTimer to schedule one off jobs that get executed in the future, and recurringTimer to auto-repeat these jobs. The duration can be given in nanoseconds (or seconds if that is more convenient for you). Use cancelTimer to remove a previously set timer.

If you’re a power user that wants precise control over the canister's global timer, you can define a system function called timer yourself, and establish either a super simple or an elaborately customized mechanism. If you want to avoid any timer-related code in your canister, you can pass the -no-timer flag to moc and stop paying for what you don't use. See more details in the PR discussion here.

As a first customer, Motoko playground will use timers to control canister expiration soon.

This feature will be included in the next release of dfx, but is also available in the current release of the Motoko compiler. Have fun with timers!

Function: fromIter

Header image

Base library: improved documentation and testing

The languages team was hard at work during the end of year and the start of this year, amongst other things, at testing and documenting the base library en masse! We’ve added a bunch of descriptions to the library functions, as well as runnable examples so devs can quickly figure out how to use the different APIs. We’ve also expanded the unit test coverage of these library modules to give developers a stronger level of confidence in our modules. We’ll be cutting a release of motoko-base soon to get these changes out to you guys, and will also continue to improve the documentation and testing of our libraries.

See you next time!

We'll be back with more features and updates in a week’s time. Happy building and happy new year!

– DFINITY Languages team