2018年12月22日 星期六

java promise

https://my.oschina.net/andylucc/blog/608499

http://ifeve.com/promise-future-callback/

https://github.com/hprose/hprose-java/wiki/%E5%BC%82%E6%AD%A5%E7%BC%96%E7%A8%8B%E2%80%94%E2%80%94Promise

https://juejin.im/post/5b126065e51d4506bd72b7cc

https://www.infoq.cn/article/design-patterns-promise https://www.cnkirito.moe/future-and-promise/


interface Closure<E, T> {
    public T callback(E in);
  
    public void error(Error err);
}


public class Promise<E> {
       
    protected int status = 0;   
    protected ArrayList<Closure> jobList = new ArrayList<>();
    protected Closure<Promise, Void> job;
    protected E data;
   
    public Promise(Closure job){
        this.job = job;

        // 暴露 resolve, reject
        this.job.callback(this);
    }

    private Promise() {
       
    }
   
    public void resolve(E e){
       
    }
   
    public void reject(String err){
       
    }
   
    protected void reject(Error err){
       
    }
   
    public Promise done(Closure c){
       
        return (new Promise<E>());
    }
   
    public Promise error(Closure c){
       
        return (new Promise<E>());
    }   
}