Computation with time limit

后端 未结 9 2293
你的背包
你的背包 2021-01-02 12:08

I\'m trying to write a construct which allows me to run computations in a given time window. Something like:

def expensiveComputation(): Double = //... some          


        
9条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-02 12:55

    If you want to run the task in the current thread and if there should be no other threads involved, you would have to check whether the time limit is over inside of expensiveComputation. For example, if expensiveComputation is a loop, you could check for the time after each iteration.

提交回复
热议问题