-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (40 loc) · 1.01 KB
/
index.js
File metadata and controls
49 lines (40 loc) · 1.01 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
'use strict';
var child_process = require('child_process');
var child = null;
function initialize(cb) {
child = child_process.fork(__dirname+'/fork.js');
child.once('message', function (message) {
cb(message);
});
}
function close() {
child.kill();
child = null;
}
function solve(facelets, maxDepth, timeOut, useSeparator, cb) {
child.send({solve: {facelets: facelets, maxDepth: maxDepth, timeOut: timeOut, useSeparator: useSeparator}});
child.once('message', function (message) {
if (typeof message === 'number') {
cb(message, null); // error
} else {
cb(null, message);
}
});
}
function randomCube(cb) {
child.send({randomCube: true});
child.once('message', function (message) {
cb(null, message);
});
}
function verify(cb) {
child.send({verify: true});
child.once('message', function (message) {
cb(null, message);
});
}
module.exports.initialize = initialize;
module.exports.close = close;
module.exports.solve = solve;
module.exports.randomCube = randomCube;
module.exports.verify = verify;