Failsafe : 执行 void 方法并根据成功/失败返回结果

问题描述

我正在使用 Failsafe 框架 (link) 来执行一个方法。我的用例是执行 void 方法 x 次并根据执行结果返回 successfailure。下面是我的(伪)代码的样子:

public void methodThatNeedsToExecute(){..}

public String failsafeWrapper(){
    RetryPolicy<String> retryPolicy = new RetryPolicy<>().withMaxRetries(50);
    return Failsafe.with(retryPolicy)
        .onSuccess(return "success") // how to do this?
        .onFailure(return "failure") //how to do this?
        .get(() -> methodThatNeedsToExecute()); //this won't work

}

我可以使用 runFailsafe 方法来执行我的 void 方法(即 methodThatNeedsToExecute())。但是,如何根据重试的执行方式返回某些内容

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)