Skip to content

Instantly share code, notes, and snippets.

@gabhi
Created June 4, 2014 21:01
Show Gist options
  • Save gabhi/cc5d8ec2f67b1f7383bd to your computer and use it in GitHub Desktop.
Save gabhi/cc5d8ec2f67b1f7383bd to your computer and use it in GitHub Desktop.
singleton + expressjs + javascript
var constants = require('../config/constants');
var url = constants.APP_URL;
var soap = require('soap');
var singleton = function singleton() {
var instance = null;
soap.createClient(url, function(err, client) {
if (err) {
console.log(err);
instance = null;
} else {
instance = client;
}
});
this.getClientInstance = function() {
return instance;
};
if (singleton.caller != singleton.getInstance) {
throw new Error("This object cannot be instanciated");
}
}
singleton.instance = null;
singleton.getInstance = function() {
if (this.instance === null) {
this.instance = new singleton();
}
return this.instance;
}
module.exports = singleton.getInstance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment