@xolvio/fiber-utils
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -237,2 +237,21 @@ describe('fiber-utils', function () { | ||
describe('when the object already has a function with the same name', function () { | ||
it('uses an unused name', function () { | ||
var myFunc = myObject.myFunc; | ||
var existingFunc = function () {}; | ||
myObject.myFuncAsync = existingFunc; | ||
myObject.myFuncSync = existingFunc; | ||
fiberUtils.wrapAsyncObject(myObject, ['myFunc'], { | ||
wrapAsync: wrapAsync | ||
}); | ||
expect(myObject.myFuncAsync).toBe(existingFunc); | ||
expect(myObject.myFuncSync).toBe(existingFunc); | ||
expect(myObject.myFuncAsync2).toBe(myFunc); | ||
expect(myObject.myFuncSync2).toBeDefined(); | ||
expect(myObject.myFuncSync2.isWrapped).toBe(true); | ||
}); | ||
}); | ||
describe('options', function () { | ||
@@ -239,0 +258,0 @@ it('"syncByDefault: false" makes the default function async', function () { |
15
index.js
@@ -62,4 +62,15 @@ var Fiber = require('fibers'); | ||
var syncMethod = wrapAsync(asyncMethod, object); | ||
object[propertyName + 'Async'] = asyncMethod; | ||
object[propertyName + 'Sync'] = syncMethod; | ||
var asyncMethodName = propertyName + 'Async'; | ||
if (object[asyncMethodName]) { | ||
asyncMethodName += '2'; | ||
} | ||
object[asyncMethodName] = asyncMethod; | ||
var syncMethodName = propertyName + 'Sync'; | ||
if (object[syncMethodName]) { | ||
syncMethodName += '2'; | ||
} | ||
object[syncMethodName] = syncMethod; | ||
if (syncByDefault) { | ||
@@ -66,0 +77,0 @@ object[propertyName] = syncMethod; |
{ | ||
"name": "@xolvio/fiber-utils", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Fiber utilities to convert async functions to sync ones", | ||
@@ -24,7 +24,11 @@ "keywords": [ | ||
"jest": { | ||
"moduleFileExtensions": ["js", "json", "node"] | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"node" | ||
] | ||
}, | ||
"dependencies": { | ||
"fibers": "^1.0.6", | ||
"underscore": "~1.8.3" | ||
"underscore": "^1.8.3" | ||
}, | ||
@@ -31,0 +35,0 @@ "devDependencies": { |
11749
325
+ Addedunderscore@1.13.7(transitive)
- Removedunderscore@1.8.3(transitive)
Updatedunderscore@^1.8.3