@yangyuhe/hope
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

hope.js

Hope.js is a implementation for Promise/A+ specification which pass Promises/A+ Compliance Test Suite.

install

npm install @yangyuhe/hope --save

use

  1. with typescript
import {Hope} from "hope";
let hope=new Hope((resolve,reject)=>{
    resolve("success");
}).then(res=>{
    console.log(res);//output "success"
});
  1. with commonjs
let Hope=require("hope").Hope;
let hope=new Hope((resolve,reject)=>{
    resolve("success");
}).then(res=>{
    console.log(res);//output "success"
});
  1. in browser
    import script of hope.js
<script src="...path/hope.js"></script>
<script>
    let hope=new Hope((resolve,reject)=>{
        resolve("success");
    }).then(res=>{
        console.log(res);//output "success"
    });
</script>

API

Hope.js 's API is the same as normal Promise's api in Browser except with one extra api:

Hope.any(hope:Hope[]):Hope

the any method will resolve if any of hopes resolved and will reject if all of hopes rejected. when resolve, the parameter will be the first resolved value and when reject, then parameter will be a array which contains all reasons rejected in order of hopes passed in.

Readme

Keywords

none

Package Sidebar

Install

npm i @yangyuhe/hope

Weekly Downloads

2

Version

1.1.1

License

ISC

Unpacked Size

60.3 kB

Total Files

13

Last publish

Collaborators

  • yangyuhe