Repository navigation
Expand file tree
/
Copy pathTestCommandsTwo.js
More file actions
98 lines (90 loc) · 3.36 KB
/
Copy pathTestCommandsTwo.js
File metadata and controls
98 lines (90 loc) · 3.36 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* GNU AGPL-3.0 License
*
* Copyright (c) 2021 - present core.ai . All rights reserved.
* Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
* for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
*
*/
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, node: true */
/*global */
(function () {
"use strict";
/**
* @private
* @type {DomainManager}
* The DomainManager passed in at init.
*/
var _domainManager = null;
/**
* @private
* Handler for test.reverseAsync command. Reverses the specified string
* and then returns the result asynconously.
* @param {string} s String to reverse.
* @param {Function} cb Callback function of the form cb(err, response)
*/
function cmdTestReverseAsync(s, cb) {
var result = s.split("").reverse().join("");
process.nextTick(function () {
cb(null, result);
});
}
/**
* @private
* Handler for test.reverseAsyncWithProgress command. Reverses the specified string
* and then returns the result asynconously, but launches progress event before that.
* @param {string} s String to reverse.
* @param {Function} cb Callback function of the form cb(err, response)
* @param {Function} pcb Progress callback function of the form pcb(message)
*/
function cmdTestReverseAsyncWithProgress(s, cb, pcb) {
var result = s.split("").reverse().join("");
process.nextTick(function () {
pcb("progress");
process.nextTick(function () {
cb(null, result);
});
});
}
/**
* Initializes the test domain with an additional test command.
* @param {DomainManager} DomainManager The DomainManager for the server
*/
function init(DomainManager) {
_domainManager = DomainManager;
if (!_domainManager.hasDomain("test")) {
_domainManager.registerDomain("test", {major: 0, minor: 1});
}
_domainManager.registerCommand(
"test",
"reverseAsync",
cmdTestReverseAsync,
true,
"reverses the specified string using an async call on the server",
[{name: "s", type: "string"}],
[{name: "reversedString", type: "string"}]
);
_domainManager.registerCommand(
"test",
"reverseAsyncWithProgress",
cmdTestReverseAsyncWithProgress,
true,
"reverses the specified string using an async call on the server and calls a progress event before",
[{name: "s", type: "string"}],
[{name: "reversedString", type: "string"}]
);
}
exports.init = init;
}());