-
-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathserver.js
83 lines (71 loc) · 1.73 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
var async = require('async');
var path = require('path');
var sandboxHelper = require('../helpers/sandbox.js');
// Private fields
var modules, self, __private = {}, shared = {};
__private.loaded = false;
/**
* Initializes Server.
* @memberof module:server
* @class
* @classdesc Main server methods.
* @param {scope} scope - App instance.
* @param {function} cb - Callback function.
* @return {setImmediateCallback} Callback function with `self` as data.
*/
// Constructor
function Server (cb, scope) {
self = this;
setImmediate(cb, null, self);
}
// Public methods
/**
* Calls helpers.sandbox.callMethod().
* @implements {sandboxHelper.callMethod}
* @param {function} call - Method to call.
* @param {} args - List of arguments.
* @param {function} cb - Callback function.
*/
Server.prototype.sandboxApi = function (call, args, cb) {
sandboxHelper.callMethod(shared, call, args, cb);
};
// Events
/**
* Modules are not required in this file.
* @param {modules} scope - Loaded modules.
*/
Server.prototype.onBind = function (scope) {
modules = true;
};
/**
* Sets private variable loaded to true.
*/
Server.prototype.onBlockchainReady = function () {
__private.loaded = true;
};
/**
* Sets private variable loaded to false.
* @param {function} cb
* @return {setImmediateCallback} cb
*/
Server.prototype.cleanup = function (cb) {
__private.loaded = false;
return setImmediate(cb);
};
/**
* Returns private loaded value
* @return {boolean} loaded
*/
Server.prototype.isLoaded = function () {
return __private.loaded;
};
/**
* Returns true if modules are loaded.
* @return {boolean} modules loaded
*/
Server.prototype.areModulesReady = function () {
return !!modules;
};
// Export
module.exports = Server;