Can Tracker or Deps be used on Meteor Server side?

798 views
Skip to first unread message

Richard MENG

unread,
Sep 11, 2014, 6:55:48 AM9/11/14
to meteo...@googlegroups.com
Hi theres,

I saw Meteor Doc indicates that the Tracker are 'client' Api, are those supposed to be used in Server side ?

Further, I got an exception when use Tracker and Meteor method to set a timer, below is an exception
I20140911-18:23:45.992(8)? Exception from Tracker recompute function: Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I20140911-18:23:45.993(8)?     at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9)
I20140911-18:23:45.993(8)?     at _.extend.get (packages/meteor/dynamics_nodejs.js:21)
I20140911-18:23:45.993(8)?     at withoutInvocation (packages/meteor/timers.js:4)
I20140911-18:23:45.993(8)?     at bindAndCatch (packages/meteor/timers.js:13)
I20140911-18:23:45.994(8)?     at Object._.extend.setTimeout (packages/meteor/timers.js:29)
I20140911-18:23:45.994(8)?     at packages/troubleshooting-wan/wan-summary.js:83 <<< This is a server side JS, handling a Method call from Client side.. in this
I20140911-18:23:45.995(8)?     at packages/tracker/tracker.js:72
I20140911-18:23:45.995(8)?     at Object.Meteor._noYieldsAllowed (packages/meteor/fiber_helpers.js:11)
I20140911-18:23:45.995(8)?     at packages/tracker/tracker.js:71
I20140911-18:23:45.996(8)?     at Tracker.Computation._compute (packages/tracker/tracker.js:255)

The wan-summary.js handling a Method call from Client side, and set a ReactiveVar, to do timer..

Thanks in advance if anyone could help.

Best regards,

Ricard-

Richard MENG

unread,
Sep 11, 2014, 10:10:53 AM9/11/14
to meteo...@googlegroups.com
Can anyone shed a light on this?

Thank you!

Emily Stark

unread,
Sep 11, 2014, 11:30:45 AM9/11/14
to meteo...@googlegroups.com
It looks there are two issues here:

1. The "Meteor code must always run within a Fiber" message is probably because you are using `setTimeout` instead of `Meteor.setTimeout`. The latter wraps its function in a fiber for you. See http://docs.meteor.com/#timers

2. Tracker is not supported on the server, in the sense that we don't test it, don't go out of our way to support it, and I'm not sure that anyone has ever sat down and convinced themselves that the Tracker code is correct on the server. That said, I've used `Tracker.autorun` on the server before and I think it is basically correct because it doesn't allow the computation to yield. (Which means, by the way, that you can't do a database read inside the computation.) So I don't think that server-side Tracker is causing your problem here, even though it is in a "use-at-your-own-risk" state.

Hope that helps,
Emily

--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

David Greenspan

unread,
Sep 11, 2014, 4:34:29 PM9/11/14
to meteo...@googlegroups.com
I think Tracker is actually at least partially at fault for not using Meteor.setTimeout itself.

Richard MENG

unread,
Sep 11, 2014, 8:14:20 PM9/11/14
to meteo...@googlegroups.com
Thanks for reply!

And I did use the Meteor.setTimeout, it's in the Tracker.autorun, the exception stack tells that:


I20140911-18:23:45.993(8)?     at bindAndCatch (packages/meteor/timers.js:13)

Probably Tracker is not for Server.. If that is the case, which is the correct way to do reactive-things in the server end?


Thanks,

Richard-

Andrew Mao

unread,
Sep 11, 2014, 8:58:11 PM9/11/14
to meteo...@googlegroups.com
Tracker (previously Deps) is not exported on the server, see https://github.com/meteor/meteor/issues/1798.

Richard MENG

unread,
Sep 11, 2014, 9:27:40 PM9/11/14
to meteo...@googlegroups.com
YES! It looks so, and with this exception in mind, I would never use Tracker/Deps in server end.. :)

But if there is a way to reactive logic in server end, it could be more charming for Meteor..


Thanks1

Paul Cuciureanu

unread,
Nov 14, 2014, 11:21:38 PM11/14/14
to meteo...@googlegroups.com
One use case for server side Tracker.autorun would be gaming, i.e.: if some conditions get met, mark level as complete.

I believe there are some game designers on this mailing-list. How do you guys monitor state changes to allow for progression. Points, badges, leader boards?

Right now I have a Tracker.autorun(checkStatusOfCurrentLevelAndMarkAsComplete) in Template.*.created

There may be better ways to do this? 

Paul Cuciureanu

unread,
Nov 14, 2014, 11:34:35 PM11/14/14
to meteo...@googlegroups.com
Need to use this.autorun in .created/.rendered instead of Tracker.autorun as per https://github.com/meteor/meteor/issues/2057
Reply all
Reply to author
Forward
0 new messages