Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

run-async

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

run-async - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

49

index.js

@@ -21,14 +21,43 @@ 'use strict';

return function () {
var async = false;
var args = arguments;
var promise = new Promise(function (resolve, reject) {
var resolved = false;
const wrappedResolve = function (value) {
if (resolved) {
console.warn('Run-async promise already resolved.')
}
resolved = true;
resolve(value);
}
var rejected = false;
const wrappedReject = function (value) {
if (rejected) {
console.warn('Run-async promise already rejected.')
}
rejected = true;
reject(value);
}
var usingCallback = false;
var callbackConflict = false;
var contextEnded = false;
var answer = func.apply({
async: function () {
async = true;
if (contextEnded) {
console.warn('Run-async async() called outside a valid run-async context, callback will be ignored.');
return function() {};
}
if (callbackConflict) {
console.warn('Run-async wrapped function (async) returned a promise.\nCalls to async() callback can have unexpected results.');
}
usingCallback = true;
return function (err, value) {
if (err) {
reject(err);
wrappedReject(err);
} else {
resolve(value);
wrappedResolve(value);
}

@@ -39,9 +68,15 @@ };

if (!async) {
if (usingCallback) {
if (isPromise(answer)) {
answer.then(resolve, reject);
console.warn('Run-async wrapped function (sync) returned a promise but async() callback must be executed to resolve.');
}
} else {
if (isPromise(answer)) {
callbackConflict = true;
answer.then(wrappedResolve, wrappedReject);
} else {
resolve(answer);
wrappedResolve(answer);
}
}
contextEnded = true;
});

@@ -48,0 +83,0 @@

4

package.json
{
"name": "run-async",
"version": "2.3.0",
"version": "2.4.0",
"description": "Utility method to run function either synchronously or asynchronously using the common `this.async()` style.",

@@ -27,4 +27,4 @@ "main": "index.js",

"devDependencies": {
"mocha": "^3.1.2"
"mocha": "^7.1.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc