Created
April 12, 2016 19:53
-
-
Save glaforge/b10756f3fc183c1c9733fc3281fcd3c3 to your computer and use it in GitHub Desktop.
Another example combining JDeferred with Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab('org.jdeferred:jdeferred-core:1.2.4') | |
import org.jdeferred.* | |
import org.jdeferred.impl.* | |
def d = new DeferredObject() | |
def p = d.promise() | |
// gotta be explicit and can't use Groovy closures: | |
// DoneCallback / DoneFilter / DonePite are ambiguous | |
// in terms of signature, for SAM type coercion | |
def filtered = p.then(new DoneFilter<Integer, Integer>() { | |
Integer filterDone(Integer result) { | |
result * 10 | |
} | |
}).done { result -> | |
// result would be original * 10 | |
assert result == 30 | |
} | |
d.resolve(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment