Skip to content

Commit

Permalink
Added $.promisify() and PROMISIFY() methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
petersirka committed Jul 3, 2024
1 parent 0f0f75d commit 16fbc80
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@ Options.prototype.action = function(schema, payload) {
return F.action(schema, payload, this.controller);
};

Options.prototype.promisify = function(fn, a, b, c) {
var $ = this;
return new Promise(function(resolve) {

var callback = function(err, response) {
if (err)
$.invalid(err);
else
resolve(response);
};

if (c !== undefined)
fn(a, b, c, callback);
else if (b !== undefined)
fn(a, b, callback);
else if (a !== undefined)
fn(a, callback);
else
fn(callback);

});
};

Options.prototype.publish = function(value) {
var self = this;
var name = self.id;
Expand Down
21 changes: 21 additions & 0 deletions global.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ global.ErrorBuilder = F.TBuilders.ErrorBuilder;
global.DOWNLOAD = F.download;
global.OPENCLIENT = (url, id) => require('./openclient').create(url, id);
global.NEWMACRO = (str, nocompile, isasync) => require('./macros').compile(str, nocompile, isasync);
global.PROMISIFY = function(fn, a, b, c) {
return new Promise(function(resolve, reject) {

var callback = function(err, response) {
if (err)
reject(err);
else
resolve(response);
};

if (c !== undefined)
fn(a, b, c, callback);
else if (b !== undefined)
fn(a, b, callback);
else if (a !== undefined)
fn(a, callback);
else
fn(callback);

});
};

global.BLOCKED = function($, limit, expire) {

Expand Down

0 comments on commit 16fbc80

Please sign in to comment.