Created
June 4, 2014 21:01
-
-
Save gabhi/cc5d8ec2f67b1f7383bd to your computer and use it in GitHub Desktop.
singleton + expressjs + javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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