我正在尝试使用RxJS(使用JQuery扩展),我正在尝试解决以下用例:
鉴于我有两个按钮(A和B),如果在给定的时间范围内点击某个"秘密组合",我想打印一条消息.例如,"秘密组合"可以是在5秒内点击"ABBABA".如果未在5秒内输入组合,则应显示超时消息.这就是我目前拥有的:
var secretCombination = "ABBABA";
var buttonA = $("#button-a").clickAsObservable().map(function () { return "A"; });
var buttonB = $("#button-b").clickAsObservable().map(function () { return "B"; });
var bothButtons = Rx.Observable.merge(buttonA, buttonB);
var outputDiv = $("#output");
bothButtons.do(function (buttonName) {
outputDiv.append(buttonName);
}).bufferWithTimeOrCount(5000, 6).map(function (combination) {
return combination.reduce(function (combination, buttonName) {
return combination + buttonName;
}, "");
}).map(function (combination) {
return combination === secretCombination;
}).subscribe(function (successfulCombination) {
if (successfulCombination) {
outputDiv.html("Combination unlocked!");
} else {
outputDiv.html("You're not fast enough, try again!");
}
});
Run Code Online (Sandbox Code Playgroud)
虽然这很好用,但这并不是我想要的.我需要bufferWithTimeOrCount …
假设我有一个这样的map(m):
(def m {:a 1 :b 2 :c {:d 3 :e 4} :e { ... } ....})
Run Code Online (Sandbox Code Playgroud)
我想创建一个新的地图只含有:a,:b并:d从m,即结果应该是:
{:a 1 :b 2 :d 3}
Run Code Online (Sandbox Code Playgroud)
我知道我可以select-keys轻松地使用:a和:b:
(select-keys m [:a :b])
Run Code Online (Sandbox Code Playgroud)
但是有什么好办法:d呢?我正在寻找这样的东西:
(select-keys* m [:a :b [:c :d]])
Run Code Online (Sandbox Code Playgroud)
Clojure中是否存在这样的功能或推荐的方法是什么?
我有一个发布事件E1的A类.在使用注释的同一应用程序中,B类消耗E1 @RabbitListener.B做了一些事情,然后发布了由C等消耗的事件E2(形成一个流程链).
我想做的是两件事:
RabbitListener's以便不执行作为E1发布结果的整个过程.我只想断言A做了它应该做的并发布了E1.我已设法通过设置来适应这一点spring.rabbitmq.listener.auto-startup=false.RabbitListerner正确配置了B. 但我再次不希望C被称为E2的副作用.我知道我可以使用模拟做到这一点但最好我想测试真实的交易并使用实际的组件(包括将消息发送到我的案例中运行在Docker中的实际RabbitMQ实例).
我可以在Spring Boot中以一种很好的方式实现这一目标吗?或者是否可能建议使用@RabbitListenerTest并确实使用模拟?
我正在使用容器库,我试图在REPL中使用这种方法从集合中提取第一个元素:
let initialSet = insert "x" empty
let setWithTwoElems = insert "y" initialSet
elemAt 0 (filter (\v -> v == "x") setWithTwoElems)
Run Code Online (Sandbox Code Playgroud)
如果传递给过滤器的谓词与Set中的任何元素都不匹配,那么这是行不通的.如果我这样做:
elemAt 0 (filter (\v -> v == "z") setWithTwoElems)
Run Code Online (Sandbox Code Playgroud)
它会爆炸说:
"*** Exception: Set.elemAt: index out of range
CallStack (from HasCallStack):
error, called at libraries/containers/Data/Set/Base.hs:1186:16 in containers-0.5.7.1:Data.Set.Base
Run Code Online (Sandbox Code Playgroud)
哪种蔑视使用Haskell的目的?我想要类似于elemAt(或只是first)返回Maybe结果的东西.
我怎样才能做到这一点?
我正在努力学习Haskell,我正在玩IORef,我试图保存并查找记录.我的代码看起来像这样(注意我在这个例子中选择了"String"作为IORef类型只是为了方便和简介,在我的实际代码中我正在使用记录.而且还忽略我使用的是Set而不是一张地图,我会改变一下):
module MyTest where
import Data.IORef
import Data.Set
import Data.Foldable (find)
type State = (Set String)
type IORefState = IORef State
saveStringToState :: IO IORefState -> String -> IO String
saveStringToState stateIO string = do
state <- stateIO
atomicModifyIORef
state
(\oldStrings ->
let updatedStrings = insert string oldStrings
in (updatedStrings, updatedStrings))
stringsState <- readIORef state :: IO State
putStrLn ("### saved: " ++ show stringsState)
return string
findStringInState :: IO IORefState -> String -> IO (Maybe String)
findStringInState …Run Code Online (Sandbox Code Playgroud) 我想在Flux完成后返回一个值(或发布者)。这是一个带有(伪)代码的示例,类似于我所追求的:
val myId : Mono<String> = fetchMyId()
myId.flatMap { id ->
someFlux.map { .. }.doOnNext { ... }.returnOnComplete(Mono.just(id))
}
Run Code Online (Sandbox Code Playgroud)
即我想id在someFlux完成后返回。该returnOnComplete函数是虚构的并且不存在(有一个doOnComplete函数,但它是为了副作用)这就是我问这个问题的原因。我怎样才能做到这一点?
reactive-programming spring-boot project-reactor spring-webflux
创建Google容器引擎(GKE)群集时,您可以指定要在群集中使用的数量和类型的计算机.
我正在使用Spring Data MongoDB(来自Spring Boot的spring-boot-starter-data-mongodb 1.5.2.RELEASE)和MongoDB 3.4.9,并定义了一个类似于以下内容的存储库:
interface MyMongoDBRepository extends CrudRepository<MyDTO, String> {
Stream<MyDTO> findAllByCategory(String category);
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个MyService与该存储库交互的服务:
@Service
class MyService {
@Autowired
MyMongoDBRepository repo;
public void doStuff() {
repo.findAllByCategory("category")
.map(..)
.filter(..)
.forEach(..)
}
}
Run Code Online (Sandbox Code Playgroud)
数据库中有很多数据,有时会发生此错误:
2018-01-01 18:16:56.631 ERROR 1 --- [ask-scheduler-6] o.s.integration.handler.LoggingHandler : org.springframework.dao.DataAccessResourceFailureException:
Query failed with error code -5 and error message 'Cursor 73973161000 not found on server <mongodb-server>' on server <mongodb-server>;
nested exception is com.mongodb.MongoCursorNotFoundException:
Query failed with error code -5 and error message …Run Code Online (Sandbox Code Playgroud) 是否可以列出具有特定模式的带注释标签,而无需从 Git 克隆或拉取整个存储库?
我想做的基本上是这样的:
git tag -l "*pattern*" | sort -r
Run Code Online (Sandbox Code Playgroud)
无需克隆存储库。
我知道您可以用来ls-remote列出标签,即
git ls-remote --tags git://github.com/git/git.git
Run Code Online (Sandbox Code Playgroud)
但这似乎并没有给我提供搜索的选项*pattern*(如果我没记错的话)。
有没有办法做到这一点?
背景
我正在尝试使用Spring Project Reactor 3.3.0 版实现类似于简单的非阻塞速率限制器的东西。例如,要将数量限制为每秒 100 个请求,我使用以下实现:
myFlux
.bufferTimeout(100, Duration.ofSeconds(1))
.delayElements(Duration.ofSeconds(1))
..
Run Code Online (Sandbox Code Playgroud)
这适用于我的用例,但如果订阅者没有跟上myFlux发布者的速度,它会(正确地)抛出OverflowException:
reactor.core.Exceptions$OverflowException: Could not emit buffer due to lack of requests
at reactor.core.Exceptions.failWithOverflow(Exceptions.java:215)
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Assembly trace from producer [reactor.core.publisher.FluxLift] :
reactor.core.publisher.Flux.bufferTimeout(Flux.java:2780)
Run Code Online (Sandbox Code Playgroud)
在我的情况下,重要的是所有元素都被订阅者消耗,因此例如降低背压 ( onBackpressureDrop()) 是不可接受的。
题
有没有办法,而不是在背压下丢弃元素,只是暂停消息的发布,直到订阅者赶上?在我的情况下myFlux,发布了一个有限但大量的元素,这些元素持久存在于持久数据库中,因此恕我直言,不应该要求删除元素。
spring ×3
spring-boot ×3
haskell ×2
java ×2
backpressure ×1
clojure ×1
frp ×1
git ×1
ioref ×1
javascript ×1
kubernetes ×1
mongodb ×1
rabbitmq ×1
rxjs ×1
shared-state ×1
spring-amqp ×1