Peter Dinker
Peter Dinker

Reputation: 273

Delay in Meteor

I'm having trouble delaying a function in Meteor that returns a message from a collection in the database. Right now, in the MeteorPad example link below, a message is posted from the user and it is displayed and faded in to everyone in the display.

MeteorPad Project Example

JS

Template.textDisplay.helpers({
message: function () {
return Database.findOne({}, { sort: { date: -1} });
     }
});


Database.insert({
  text: message,
  date: new Date()
});

HTML

<template name="textDisplay">  
<div class="secret-display">
{{secret.text}}
</div>
</template>

Unfortunately if many people are sending a message at the same time the message can't be seen as there isn't enough time for the fade to finish.. it would need a 1 second delay between messages with some sort of queue.

I have tried setInterval for the delay which did not work in this case as a queue is needed. Is a queue of collections possible?

Upvotes: 1

Views: 563

Answers (1)

FullStack
FullStack

Reputation: 6020

Using setInterval or setTimeout in the helper won't work. You need to use it in onCreated or onRendered, and then pass it to the helper with a Session or ReactiveVar

Upvotes: 1

Related Questions