How can I “sleep” a Dart program

前端 未结 7 2239
梦谈多话
梦谈多话 2020-12-12 23:39

I like to simulate an asynchronous web service call in my Dart application for testing. To simulate the randomness of these mock calls responding (possibly out of order) I\

7条回答
  •  孤城傲影
    2020-12-13 00:00

    It's not always what you want (sometimes you want Future.delayed), but if you really want to sleep in your Dart command-line app, you can use dart:io's sleep():

    import 'dart:io';
    
    main() {
      sleep(const Duration(seconds:1));
    }
    

提交回复
热议问题