if child is already resolved/rejected — no need to notify it

This commit is contained in:
Vladimir Krivosheev
2017-04-05 17:19:48 +02:00
parent 269ed5682d
commit cecbb34f60
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,6 +78,10 @@ open class AsyncPromise<T> : Promise<T>, Getter<T> {
override fun notify(child: AsyncPromise<in T>) {
LOG.assertTrue(child !== this)
if (child.state != State.PENDING) {
return
}
when (state) {
State.PENDING -> {
addHandlers(Consumer({ child.catchError { child.setResult(it) } }), Consumer({ child.setError(it) }))