Skip to content

Instantly share code, notes, and snippets.

@jorgeuriarte
Created October 12, 2016 12:18
Show Gist options
  • Save jorgeuriarte/badab813996c241e521d35c1ea3f9f6a to your computer and use it in GitHub Desktop.
Save jorgeuriarte/badab813996c241e521d35c1ea3f9f6a to your computer and use it in GitHub Desktop.
Ejemplo de contexto de closures arrastrado en Groovy
@Grab("io.vertx:vertx-core:3.3.3")
import io.vertx.core.Vertx
def schedulerId
def vertx = Vertx.vertx()
(1..10).each { it ->
vertx.setTimer(2000, {
println """
Hola, este es ${schedulerId}
"""
})
sleep(500)
schedulerId = it
println "schedulerId <= ${it}"
}
@jorgeuriarte
Copy link
Author

schedulerId <= 1
schedulerId <= 2
schedulerId <= 3

            Hola, este es 3

schedulerId <= 4

            Hola, este es 4

schedulerId <= 5

            Hola, este es 5

schedulerId <= 6

            Hola, este es 6

schedulerId <= 7

            Hola, este es 7

schedulerId <= 8

            Hola, este es 8

schedulerId <= 9

            Hola, este es 9

schedulerId <= 10
Result: 1..10
            Hola, este es 10


            Hola, este es 10


            Hola, este es 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment