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 608039f commit dead133
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions builders.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,29 @@ SchemaOptions.prototype = {

var SchemaOptionsProto = SchemaOptions.prototype;

SchemaOptionsProto.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);

});
};

SchemaOptionsProto.action = function(schema, data) {

var c = schema[0];
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- extended icon validator by adding support for `tic` keyword
- fixed link generator for email and phone numbers in `Markdown`
- improved `Number.pluralize()` method
- added `PROMISIFY(fn, [a], [b])` method
- added `$.promisify(fn, [a], [b])` method

========================
0.0.96
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20841,6 +20841,28 @@ Api.evaluate('TotalAPI,TAPI', function(opt, next) {
REQUEST(req);
});

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);

});
};

UIDGENERATOR_REFRESH();
require('./textdb-querybuilder');
require('./sourcemap');
Expand Down

0 comments on commit dead133

Please sign in to comment.