java - How to customize subscribe() behaviour with a Sink in Project Reactor?
问题描述
For a Flux
you can specify a custom action that happens upon subscription. For instance Flux.create(emitter -> someApi.setCallback(emitter::next))
will set some API hooks upon subscription.
How can we have a custom subscription action like this for a sink? E.g. Sinks.unsafe().many().unicast().onBackpressureBuffer(someAction)
?
I've managed to make it work using Flux.concat(Mono.fromRunnable(someAction), sink)
but I imagine that adds unnecessary overhead so not ideal.
解决方案
您可以使用doOnSubscribe
运算符:
sink.asFlux().doOnSubscribe(someAction)
推荐阅读
- html - 如何使用css正确定位选择元素和图标?
- regex - VSCode 正则表达式删除函数调用
- php - ajax调用期间禁止Yii2 403
- python - Re.sub 重叠 python
- javascript - 从 Binance API 获取数据到 Javascript 数组
- javascript - ul 内的导航项,下拉按钮不显示水平 li 元素的滚动条
- c# - 依赖项未加载 Visual Studio 2019
- ios - 如何在 UITabBarController 中垂直居中系统图像
- javascript - 找到相同的提供者 ID 并合并为一个,并将相同提供者 ID 的服务合并到一个提供者对象数组中
- php - 如何在 Carbon 中计算剩余几天或最后几天