New Meteor.js 2.10 and the Async Tracker Feature

Gabriel Grubba
Meteor Blog
Published in
2 min readJan 17, 2023

--

A new Meteor.js has landed with great updates regarding the React Skeletons, MongoDB type definitions, and the possibility to run async reactive code within a Tracker.autorun.

As for our usual update on our road to a fibers-free MeteorJS, for this release, the only new feature that we have is now the possibility to run async code in a Tracker.autorun.

Async Tracker

Before discussing what has changed, it is necessary to give context about how we did in the past. This came from our docs before 2.10:

Tracker.autorun can accept an async callback function. However, the async callback function will only be dependent on reactive functions called prior to any called functions that return a promise.

That would translate into:

The example below is not dependent on reactive changes to the Meteor.users collection. Because it is dependent on nothing reactive, it will run only once:

Tracker.autorun(async function example1() {
let asyncData = await asyncDataFunction();
let users = Meteor.users.find({}).fetch();
});

Before, we would need to do some workaround to make this reactive, placing all reactive calls first and then getting async functions. This was not as ergonomic as we wanted it to be and would translate to code looking like this:

Tracker.autorun(async function example2()  {
let users = Meteor.users.find({}).fetch();
let asyncData = await asyncDataFunction();
});

Now that you may use methods like fetchAsync() That could make reactive data hard to use. @radekmie has done this awesome PR introducing a way to deal with async code. The first example that we had to change in this new API would look like this:

Tracker.autorun(async function example1(computation) {
let asyncData = await Tracker.withComputation(computation, () => asyncDataFunction());
let users = Meteor.users.find({}).fetch();
});

Another example can be seen below using the new fetchAsync API

Tracker.autorun(async function example2(computation) {
let asyncData = await Tracker.withComputation(computation, () => asyncDataFunction());
let users = await Tracker.withComputation(computation, () => Meteor.users.find({}).fetchAsync());
});

If any doubts on how to use this new feature, come up, please reach out to us in the forums or on GitHub.

MongoDB Types update

Since v2.8.1, we have had direct TypeScript support in the Meteor.js core. In this new release, we are bringing the Core MongoDB Driver type definitions and exposing them instead of using a homemade version of those typings.

You can check it better in this PR made by @perbergland.

Other updates

Notable mentions are:

You can check other updates on the release PR or in the changelog.

Special thanks to

For making this great framework even better!

--

--