You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

synchronized-promise

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

synchronized-promise - npm Package Compare versions

Comparing version

to
0.0.3

.travis.yml

35

dist/index.js
/* 10 seconds */
const DEFAULT_TIMEOUTS = 10 * 1000;
var DEFAULT_TIMEOUTS = 10 * 1000;
/**
*
* @param {Function} func
* @param {any} [options={}]
* @param {Function} func Promise-base function that want to be transformed
* @param {Object} options Additional options
* @param {number} options.timeouts Function call timeouts
* @returns {Function}
*/
function syncPromise(func, options = {}) {
return () => {
let promiseError, promiseValue;
let hasError = false;
let args = Array.isArray(options.args) ? options.args : [options.args];
const timeouts = options.timeouts || DEFAULT_TIMEOUTS;
func.apply(this, args).then(value => {
function sp(func) {
var _this = this;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return function () {
var promiseError, promiseValue;
var hasError = false;
var timeouts = options.timeouts || DEFAULT_TIMEOUTS;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
func.apply(_this, args).then(function (value) {
promiseValue = value;
}).catch(e => {
}).catch(function (e) {
promiseError = e;
hasError = true;
});
const waitUntil = new Date(new Date().getTime() + timeouts);
var waitUntil = new Date(new Date().getTime() + timeouts);

@@ -40,2 +47,2 @@ while (waitUntil > new Date() && typeof promiseError === 'undefined') {

module.exports = syncPromise;
module.exports = sp;

13

lib/index.js

@@ -5,12 +5,11 @@ /* 10 seconds */

/**
*
* @param {Function} func
* @param {any} [options={}]
* @param {Function} func Promise-base function that want to be transformed
* @param {Object} options Additional options
* @param {number} options.timeouts Function call timeouts
* @returns {Function}
*/
function syncPromise (func, options = {}) {
return () => {
function sp (func, options = {}) {
return (...args) => {
let promiseError, promiseValue
let hasError = false
let args = Array.isArray(options.args) ? options.args : [options.args]
const timeouts = options.timeouts || DEFAULT_TIMEOUTS

@@ -41,2 +40,2 @@

module.exports = syncPromise
module.exports = sp
{
"name": "synchronized-promise",
"version": "0.0.2",
"version": "0.0.3",
"description": "Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package",

@@ -9,3 +9,3 @@ "main": "dist/index.js",

"build": "babel lib -d dist",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "ava"
},

@@ -21,2 +21,5 @@ "repository": {

],
"engines": {
"node": ">=4.2.0"
},
"author": "Yukai Huang <yukaihuangtw@gmail.com> (https://yukaii.tw)",

@@ -32,6 +35,7 @@ "license": "MIT",

"devDependencies": {
"@babel/cli": "^7.0.0-beta.39",
"@babel/core": "^7.0.0-beta.39",
"@babel/preset-env": "^7.0.0-beta.39",
"@babel/cli": "^7.0.0-beta.39"
"ava": "^0.25.0"
}
}
# synchronized-promise
[![npm version](https://badge.fury.io/js/synchronized-promise.svg)](https://badge.fury.io/js/synchronized-promise)
[![Build Status](https://travis-ci.org/Yukaii/synchronized-promise.svg?branch=master)](https://travis-ci.org/Yukaii/synchronized-promise)
Turn ES6 Promise into synchronize function call, a simple wrapper of deasync package

@@ -4,0 +7,0 @@

Sorry, the diff of this file is not supported yet