我想知道JavaScript中可用的setTimeout
函数的GWT等价物是什么?
我搜索了这个,但没有找到任何信息。
发布于 2017-11-06 14:42:28
为了删除样板代码,我创建了这个方法(需要GWT2.8或更高版本):
import com.google.gwt.user.client.Command;
import com.google.gwt.core.client.Scheduler;
public static void delay(int delayMs, Command afterDelay) {
Scheduler.get().scheduleFixedDelay(
() -> {
afterDelay.execute();
return false;
},
delayMs);
}
因此,您现在可以这样做(例如:延迟2秒,然后调用myMethod):
delay(2000, () -> myMethod());
很简单。:-)
https://stackoverflow.com/questions/8059147
复制相似问题