简体   繁体   中英

Can I stop a Play Framework promise?

Is there an advisable way to stop a Play Framework promise? For instance,

import play.api.libs.concurrent.Promise

val timeoutFuture = Promise.timeout({
    Logger.info("timeout expired.")
}, myTimeoutValue)

What would be a good way to cancel this future before myTimeoutValue expires?

If the timeout period is too long just reduce the myTimeoutValue . If you wish to interrupt the execution the is a way shown here by completing a future.

This is however questionable way to do things since you can just ignore the result of your Promise/Future if it takes too long, but since you'll have to set a period for when its too long then its just as well as putting that as the timeout value.

最后,恐怕答案是否定的-无法在超时到期之前取消此类承诺。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM