Skip to content

Instantly share code, notes, and snippets.

View possibilities's full-sized avatar

Mike Bannister possibilities

  • AI Life
  • Portland East
View GitHub Profile
Package.describe({
summary: "Moment.js packaged for Meteor"
});
Package.on_use(function (api, where) {
where = where || ['client', 'server'];
api.add_files('lib/moment/moment.js', where);
});
@possibilities
possibilities / meteor-async.md
Created August 23, 2012 22:53
Meteor Async Guide

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase:

13:25 deberg: [17:21:57] hey, i just saw your question.
13:25 eiki: [17:22:17] great - any ideas?
13:25 deberg: [17:22:19] the thing to use is futures.
13:25 eiki: [17:22:36] what's the difference?
13:25 eiki: [17:22:45] and do you know of any sample code?
13:25 deberg: [17:23:02] yeah, one place to look is the meteor HTTP package.
13:25 deberg: [17:23:11] packages/http/httpcall_server.js:64
13:25 deberg: [17:23:39] this is the basic pattern for wrapping a node callback.
13:25 eiki: [17:24:09] https://github.com/meteor/meteor/blob/master/packages/http/httpcall_server.js#L65
13:25 deberg: [17:24:35] you want to declare a new future, call future.return() inside the callback, and block the outer caller (your method) with future.wait().
AWSSum = {
load: function(module) {
var awssum = NodeModules.require('awssum');
return awssum.load(module);
},
loadSyncInterface: function(module, className) {
// Get a reference to the original interface
var interface = AWSSum.load(module)[className];
(function() {
var firstBlood = true;
Template.foof.moof = function() {
if (firstBlood) {
firstBlood = false;
doShitFirstTimeAround();
} else{
{
"meteor": {
"branch": "auth",
"patches": [
"https://github.com/meteor/meteor/pull/334.patch"
]
},
"packages": {}
}
> mrt -p 5555 ~/work/m/tmp/js-yaml 1.9.3p0
Stand back while Meteorite does it's thing
Installing Meteor
branch: https://github.com/meteor/meteor.git#master
Installing smart packages

Git For People Who Want To Git

Terms

Working tree All uncommited changes

Staging area Uncommited changes you've told git you want to include in a commit

Branches

Talk

Why I got interested Meteor

Guiding principals

Demo

Build Hipchat clone (aka backup business model for Versal)