流星计时器引发'RangeError:超出最大调用堆栈大小'

mfa*_*aag 0 meteor

我有一个基于Meteor示例'wordplay'的简单游戏.在这里,后台有一个计时器在游戏过程中倒计时.单击"播放"按钮时会调用此计时器.单击按钮时会出现此问题.

服务器端:

start_new_game: (player_id) ->

# check player_id
return unless player_id

# TODO: Avoid getting the same questions
questions = Questions.find({}, {limit: 5}).fetch()

game_id = Games.insert
  current_points: START_POINTS
  current_question: 1
  question_ids: questions.map (q) -> q._id
  time_per_question: TIME_PER_QUESTION

Players.update({ _id: player_id },
  { $set: { game_id: game_id } }
)

points_per_question = START_POINTS / NUMBER_OF_QUESTIONS
points_per_second   = points_per_question / TIME_PER_QUESTION

clock = TIME_PER_QUESTION

# BOOM: Comment following line removes problem
unless interval then interval = setInterval((-> console.log 'COMON'), 1000)
Run Code Online (Sandbox Code Playgroud)

客户端:

Template.lobby.events 
  'click button#startgame': ->
    Meteor.call 'start_new_game', current_player()._id
Run Code Online (Sandbox Code Playgroud)

错误:

W2040-19:15:24.798(1)? (STDERR) /Users/markus/.meteor/tools/0b2f28e18b/lib/node_modules/fibers/future.js:173
W2040-19:15:24.800(1)? (STDERR)                         throw(ex);
W2040-19:15:24.802(1)? (STDERR)                               ^
W2040-19:15:24.803(1)? (STDERR) RangeError: Maximum call stack size exceeded
=> Exited with code: 8
Run Code Online (Sandbox Code Playgroud)

我已经尝试过更改Meteor.setInterval为递归Meteor.setTimeout,但没有改变任何东西.

我尝试过多种浏览器和计算机.

Dav*_*don 6

根据文件:

服务器上的调用方法定义了客户端可以远程调用的函数.它们应该返回一个EJSON-able值或抛出异常.

你的CoffeeScript代码隐式返回一个间隔句柄,我认为它正在将EJSON解析器放入一个混乱中.如果你只是返回任何其他东西(用任何其他表达式结束你的方法)它可能会正常工作.