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

kew

Package Overview
Dependencies
Maintainers
4
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kew - npm Package Compare versions

Comparing version 0.1.7 to 0.2.1

22

kew.js

@@ -63,3 +63,3 @@ /**

var i
if (data && data._isPromise) {
if (data && isPromise(data)) {
this._child = data

@@ -279,2 +279,17 @@ if (this._promises) {

/**
* Return true iff the given object is a promise of this library.
*
* Because kew's API is slightly different than other promise libraries,
* it's important that we have a test for its promise type. If you want
* to test for a more general A+ promise, you should do a cap test for
* the features you want.
*
* @param {Object} obj The object to test
* @return {boolean} Whether the object is a promise
*/
function isPromise(obj) {
return !!obj._isPromise
}
/**
* Static function which creates and resolves a promise immediately

@@ -337,3 +352,3 @@ *

for (var i = 0; i < promises.length; i += 1) {
if (!promises[i] || !promises[i]._isPromise) {
if (!promises[i] || !isPromise(promises[i])) {
outputs[i] = promises[i]

@@ -427,4 +442,5 @@ counter -= 1

, fcall: fcall
, isPromise: isPromise
, resolve: resolve
, reject: reject
}
}

3

package.json
{
"name": "kew"
, "description": "a lightweight promise library for node"
, "version": "0.1.7"
, "version": "0.2.1"
, "homepage": "https://github.com/Obvious/kew"

@@ -21,2 +21,3 @@ , "authors": [

, "devDependencies": {
"q": "0.9.6",
"nodeunit": "0.7.4"

@@ -23,0 +24,0 @@ }

@@ -33,3 +33,3 @@ kew: a lightweight (and super fast) promise/deferred framework for node.js

// and then parses the actual urls from the links (using parseUrlsFromLinks())
var urlsPromise = linksPromise.then(linksPromise)
var urlsPromise = linksPromise.then(parseUrlsFromLinks)

@@ -224,2 +224,31 @@ // finally, we have a promise that should only provide us with the urls and will run once all the previous steps have ran

### `.delay()` for future promises
If you need a little bit of delay (such as retrying a method call to a service that is "eventually consistent") before doing something else, ``Q.delay()`` is your friend:
```javascript
getUrlContent(url1)
.fail(function () {
// Retry again after 200 milisseconds
return Q.delay(200).then(function () {
return getUrlContent(url1)
})
})
```
### `.fcall()` for Node.js callbacks
``Q.fcall()`` can be used to convert node-style callbacks into promises:
```javascript
Q.fcall(fs.writeFile, '/tmp/myFile', 'content')
.then(function () {
console.log('File written successfully')
})
.fail(function (err) {
console.log('Failed to write file', err)
})
```
Contributing

@@ -226,0 +255,0 @@ ------------

var Q = require('../kew')
var originalQ = require('q')

@@ -187,2 +188,20 @@ // create a promise from a literal

})
}
}
// test checking whether something is a promise
exports.testIsPromise = function (test) {
var kewPromise = Q.defer()
var qPromise = originalQ(10)
var kewLikeObject = {
promise: function () {
return 'not a promise sucka!'
},
then: function (fn) {
fn('still not a promise, brah')
}
}
test.equal(Q.isPromise(kewPromise), true, 'A Kew promise is a promise')
test.equal(Q.isPromise(qPromise), false, 'A Q promise is not a promise')
test.equal(Q.isPromise(kewLikeObject), false, 'A pretend promise is not a promise')
test.done()
}
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