GithubHelp home page GithubHelp logo

bluff's Introduction

Bluff

Build Status NPM Downloads pledge

Transform everything into a promise.

  • Standardization: Bluff helps reducing difference of implementation in your code according you are dealing with synchronous or asynchronous computations. Any value passed to Bluff is transformed into a promise. Even streams!
  • Combination: Bluff resolves when all of the promises in the iterable argument have resolved and when all or some of the the iterable argument contains no promises.

Learn more or Try it online!

Usage

var promise = require('bluff')

function readJSON(filename){
  return promise(function (resolve, reject){
    readFile(filename, 'utf8').done(function (res){
      try {
        resolve(JSON.parse(res));
      } catch (ex) {
        reject(ex);
      }
    }, reject);
  });
}

// combination example

promise(
  readJSON('package.json'),
  'and dome other text'
).then(data => {
  // do something
})

Check out examples and tests for more information.

Installation

npm install bluff --save

NPM

Question

For questions and feedback please use our twitter account. For support, bug reports and or feature requests please make sure to read our community guideline and use the issue list of this repo and make sure it's not present yet in our reporting checklist.

Contribution

Bluff is an open source project and would not exist without its community. If you want to participate please make sure to read our guideline before making a pull request. If you have any bluff-related project, component or other let everyone know in our wiki.

License

The MIT License (MIT)

Copyright (c) 2016 Olivier Wietrich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bluff's People

Contributors

bredele avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sumaita0

bluff's Issues

promises with synchronous computation

We probably should start resolving the promise when then as been called at least once. (What if we call then after the asynchronous computation occurred?)

A+ spec

if x is an object or function,

  • Let then be x.then. [3.5]
  • If retrieving the property x.then results in a thrown exception e, reject promise with e as the reason.
  • If then is a function, call it with x as this, first argument resolvePromise, and second argument rejectPromise, where:
  • If/when resolvePromise is called with a value y, run Resolver
    • If/when rejectPromise is called with a reason r, reject promise with r.
    • If both resolvePromise and rejectPromise are called, or multiple calls to the same argument are made, the first call takes precedence, and any further calls are ignored.
    • If calling then throws an exception e,
    • If resolvePromise or rejectPromise have been called, ignore it.

Otherwise, reject promise with e as the reason.
If then is not a function, fulfill promise with x.

composition issue

For an unknown reason, it seems like if the first argument of bluff is an asynchronous promise and the second a synchronous computation, the promise is never resolved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.