await 虽然简洁。因为 await 需要等待返回才继续向下执行,如果是较耗时的操作就得等待。
方式一:
await u = login();
getUserInfo(u);
otherTask(); // 必须等待 login()返回。
方式二:
login().then((u) {
getUserInfo(u);
);
otherTask(); //可以并行
我觉得 then 更加符合逻辑。
方式一:
await u = login();
getUserInfo(u);
otherTask(); // 必须等待 login()返回。
方式二:
login().then((u) {
getUserInfo(u);
);
otherTask(); //可以并行
我觉得 then 更加符合逻辑。
