asynchronous - 无法让计算在颤振上工作
问题描述
我正在尝试编写一个在后台运行 scrypt 函数的函数,因为它非常慢。我以前曾经计算过,但由于某种原因,这次我得到“未定义函数计算”
import "package:pointycastle/pointycastle.dart" as PC;
import 'dart:async';
Future<Uint8List> getKey(Uint8List password,Uint8List salt) async {
return await compute(computeKey, [password,salt]);
}
Uint8List computeKey(List<Uint8List> param) {
Uint8List salt=param[1];
Uint8List password=param[1];
PC.KeyDerivator scrypt = new PC.KeyDerivator("scrypt");
scrypt.init(new PC.ScryptParameters(16384, 8, 1, 49, salt));
return scrypt.process(password);
}
解决方案
您忘记导入颤振库package:flutter/foundation.dart
以及返回回调函数作为参数需要 a List<dynamic>
not a List<Uint8List>
。
还有一个快速的旁注:你不需要await
在你的代码中返回未来。
推荐阅读
- python - 在 RNN 中,梯度会随着多重损失而累积吗?
- prolog - 如何在这个 Prolog 程序中调试“预期的操作员”?
- php - 输入值未显示在我的电子邮件中
- stata - 如果 var1 中的值存在于 var2 中,则创建一个新变量
- parse-server - ParseServer UnhandledPromiseRejectionWarning:未处理的承诺拒绝
- google-kubernetes-engine - 无法弄清楚如何在谷歌云平台上更改此 yaml 文件
- python - 张量流 keras 中的采样 softmax
- ssl - 如何在 Kubernetes 中使用搜索域
- css - 为什么下面提到的十六进制颜色代码在视觉上与 6 位十六进制代码具有相同的颜色?
- vba - 无法过滤