Skip to content
This repository was archived by the owner on Jan 6, 2021. It is now read-only.

Commit 44b2496

Browse files
committed
Merge branch 'feature/shared_instnace' into develop
2 parents 41b22e5 + acde098 commit 44b2496

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

lib/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ exports.Server = Server;
2121
exports.Exchange = Exchange;
2222
exports.Messages = Messages;
2323

24+
/*
25+
* The global server isntance
26+
*/
27+
28+
var server = null;
29+
2430
/**
2531
* The bus
2632
*
@@ -29,7 +35,13 @@ exports.Messages = Messages;
2935

3036
function Server (a, b) {
3137

32-
if (!(this instanceof Server)) return new Server(a, b);
38+
if (!(this instanceof Server)) {
39+
if (!arguments.length && server) return server;
40+
var instance = new Server(a, b);
41+
if (!server) server = instance;
42+
return instance;
43+
}
44+
3345

3446
debug('new server', a, b);
3547

spec/lib/index-spec.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe 'Server', ->
3434

3535
Then -> expect(@Server() instanceof @Server).toBe true
3636

37+
context 'calls should return default instance', ->
38+
39+
Given -> @a = @Server()
40+
Given -> @b = @Server()
41+
Then -> expect(@a).toBe @b
42+
3743
context '(a:mixed)', ->
3844

3945
Given -> @mixed = 3000

0 commit comments

Comments
 (0)