1.1.1 • Published 6 years ago

@yangyuhe/hope v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

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.