实现cancel的逻辑。
This commit is contained in:
@@ -39,6 +39,7 @@ struct future
|
|||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
future_success_cb * cb_success;
|
future_success_cb * cb_success;
|
||||||
future_failed_cb * cb_failed;
|
future_failed_cb * cb_failed;
|
||||||
|
char is_cancelled;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct promise
|
struct promise
|
||||||
@@ -220,6 +221,10 @@ void future_destroy(struct future * f)
|
|||||||
{
|
{
|
||||||
__promise_destroy(p);
|
__promise_destroy(p);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f->is_cancelled=1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void promise_finish(struct promise * p)
|
void promise_finish(struct promise * p)
|
||||||
{
|
{
|
||||||
@@ -252,7 +257,10 @@ static void fp_stat_latency(struct _future_promise_debug* debug, int is_success)
|
|||||||
void promise_failed(struct promise * p, enum e_future_error error, const char * what)
|
void promise_failed(struct promise * p, enum e_future_error error, const char * what)
|
||||||
{
|
{
|
||||||
if(!g_FP_instance.no_stats) fp_stat_latency(&p->debug, 0);
|
if(!g_FP_instance.no_stats) fp_stat_latency(&p->debug, 0);
|
||||||
|
if(!p->f.is_cancelled)
|
||||||
|
{
|
||||||
p->f.cb_failed(error, what, p->f.user);
|
p->f.cb_failed(error, what, p->f.user);
|
||||||
|
}
|
||||||
if(!p->may_success_many_times)
|
if(!p->may_success_many_times)
|
||||||
{
|
{
|
||||||
promise_finish(p);
|
promise_finish(p);
|
||||||
@@ -263,7 +271,10 @@ void promise_failed(struct promise * p, enum e_future_error error, const char *
|
|||||||
void promise_success(struct promise * p, void * result)
|
void promise_success(struct promise * p, void * result)
|
||||||
{
|
{
|
||||||
if(!g_FP_instance.no_stats) fp_stat_latency(&p->debug, 1);
|
if(!g_FP_instance.no_stats) fp_stat_latency(&p->debug, 1);
|
||||||
|
if(!p->f.is_cancelled)
|
||||||
|
{
|
||||||
p->f.cb_success(result, p->f.user);
|
p->f.cb_success(result, p->f.user);
|
||||||
|
}
|
||||||
if(!p->may_success_many_times)
|
if(!p->may_success_many_times)
|
||||||
{
|
{
|
||||||
promise_finish(p);
|
promise_finish(p);
|
||||||
|
|||||||
Reference in New Issue
Block a user