小编All*_* Hu的帖子

有没有办法在 dart 流获得第一个结果时收到通知?

我目前有一个async执行以下操作的函数:

  1. 初始化流
  2. 调用stream.listen()并提供监听流的函数。
  3. await以便流获得第一个结果。

以下是我的函数的一些伪代码:

Future<void> initStream() async {
  // initialize stream
  var stream = getStream();
  // listen
  stream.listen((result) {
    // do some stuff here
  });
  // await until first result
  await stream.first; // gives warning
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,似乎调用算作stream.first监听流,并且流不允许被多个...监听器监听?

我尝试了一种不同的方法,使用await Future.doWhile() 如下所示的方法:

bool gotFirstResult = false;
Future<void> initStream() async {
  var stream = getStream();
  stream.listen((result) {
    // do some stuff here
    gotFirstResult = true;
  });
  await Future.doWhile(() => !gotFirstResult);
}
Run Code Online (Sandbox Code Playgroud)

这对我不起作用,我仍然不知道为什么。已成功调用,但在这种情况下从未调用Future.doWhile()提供给的函数。 …

dart flutter

8
推荐指数
2
解决办法
3834
查看次数

在 MacOS big sur 上安装 jupyterlab/jupyter 笔记本时出错

我正在尝试在我的 Mac 上安装 jupyter,但安装时遇到错误。

用于安装的命令:

pip install jupyterlab
pip install notebook
Run Code Online (Sandbox Code Playgroud)

两者都会给出类似的错误。

我承认我使用的是测试版操作系统,因此如果不支持它,我不会抱怨,只是要求确保这不是一些愚蠢的用户错误。

显示错误:

Defaulting to user installation because normal site-packages is not writeable
Collecting notebook
  Using cached notebook-6.1.4-py3-none-any.whl (9.5 MB)
Collecting traitlets>=4.2.1
  Using cached traitlets-5.0.4-py3-none-any.whl (98 kB)
Collecting prometheus-client
  Using cached prometheus_client-0.8.0-py2.py3-none-any.whl (53 kB)
Collecting argon2-cffi
  Using cached argon2-cffi-20.1.0.tar.gz (1.8 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Users/yagami/Library/Python/3.8/lib/python/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/g0/d04hk18n311bj7rw6j_r__9h0000gn/T/pip-build-env-62k24twj/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple …
Run Code Online (Sandbox Code Playgroud)

python macos pip jupyter-notebook macos-big-sur

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

dart ×1

flutter ×1

jupyter-notebook ×1

macos ×1

macos-big-sur ×1

pip ×1

python ×1