关于DART中未来执行订单的问题
这是我的代码,
Future<int> test() {
print('Start test()');
for (var i = 1; i < 100000; i++) {
for (var j = 1; j < 100000; j++) {
var k = i * j;
}
}
print('After a long running task in test()');
return Future<int>.value(1);
}
void main() {
test().then((result) => print('Done with test()'));
print('Done with main().');
}
这是输出,
Start test()
After a long running task in test()
Done with main().
Done with test()
我的问题是,在test()中长期运行的任务()''''''''''''''
Here is my code,
Future<int> test() {
print('Start test()');
for (var i = 1; i < 100000; i++) {
for (var j = 1; j < 100000; j++) {
var k = i * j;
}
}
print('After a long running task in test()');
return Future<int>.value(1);
}
void main() {
test().then((result) => print('Done with test()'));
print('Done with main().');
}
and here is the output,
Start test()
After a long running task in test()
Done with main().
Done with test()
my question is, shouldn't 'Done with main()' be printed before 'After a long running task in test()'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要跳过任务,请使用
future.microtask()
。示例:
输出:
Use
Future.microtask()
if you want skip task.Example:
Output: