Skip to content

Instantly share code, notes, and snippets.

@spion
Forked from whoeverest/async-connection.coffee
Last active December 15, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spion/5318486 to your computer and use it in GitHub Desktop.
Save spion/5318486 to your computer and use it in GitHub Desktop.
ffmpeg = require 'fluent-ffmpeg'
mongoose = require 'mongoose'
amqp = require 'amqp'
async = require 'async'
# Connect to RabbitMQ
amqpConnect = (done) ->
amqpConnection = amqp.createConnection {host: 'localhost'}
amqpConnection.on 'ready', done.bind(this, null, amqpConnection);
amqpConnection.on 'error', done.bind(this, "Failed connecting to rabbit");
# Connect to Mongo
mongoConnect = (done) ->
mongoose.connection.on 'open', done.bind(this, null, mongoose);
mongoose.connection.on 'error', done.bind(this, "Failed connecting to mongo");
# Wait for connections, if completed successfully, continue
async.parallel {amqp: amqpConnect, mongo: mongoConnect}, (err, res) ->
amqpConn = res.amqp;
mongooseDone = res.mongo;
# Wait for connections, if completed successfully, continue
async.parallel {
amqp: amqp.createConnection.bind(amqp, {host: 'localhost'}),
mongo: mongoose.openConnection.bind(mongoose)
}, (err, res) ->
amqpConn = res.amqp;
mongooseDone = res.mongo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment