allow without callbacks, issue #9

This commit is contained in:
AJ ONeal 2019-11-05 11:50:38 -07:00
parent 4e9a6c0719
commit bd5ee84e25
4 changed files with 33 additions and 4 deletions

View File

@ -22,9 +22,14 @@ GLE.init = function(fn) {
return require("./worker.js").create(); return require("./worker.js").create();
} }
var opts = fn(); var opts;
if ("function" === typeof fn) {
opts = fn();
} else if ("object" === typeof fn) {
opts = fn;
}
if (!opts || "object" !== typeof opts) { if (!opts || "object" !== typeof opts) {
throw new Error("the `Greenlock.init(fn)` function should return an object `{ greenlock, cluster }`"); throw new Error("the `Greenlock.init(fn)` function should return an object `{ packageRoot, cluster }`");
} }
// just for ironic humor // just for ironic humor

View File

@ -48,10 +48,12 @@ Master.create = function(opts) {
kickoff(); kickoff();
resolveCb(fn); resolveCb(fn);
return master; return master;
},
serve: function(fn) {
// ignore
master.ready(fn);
} }
}; };
// backwards compat starts early...
master.serve = master.ready;
return master; return master;
}; };

View File

@ -19,6 +19,17 @@ Single.create = function(opts) {
// ignore // ignore
//fn(master); //fn(master);
return single; return single;
},
serve: function(fn) {
// keeping backwards compat
if (1 === fn.length) {
single.ready(fn);
return;
}
// serving the app, right away
single.ready(function(glx) {
glx.serveApp(fn);
});
} }
}; };
// backwards compat starts now // backwards compat starts now

View File

@ -22,6 +22,17 @@ Worker.create = function() {
master: function() { master: function() {
// ignore // ignore
return worker; return worker;
},
serve: function(fn) {
// keeping backwards compat
if (1 === fn.length) {
worker.ready(fn);
return;
}
// serving the express app, right away
worker.ready(function(glx) {
glx.serveApp(fn);
});
} }
}; };
// backwards compat starts early... // backwards compat starts early...