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
// There's no proper UUID package still, so we'll deal with floats | |
m := make(map[float64]float64) | |
// This will allow us to wait for all goroutines to complete | |
doneChannel := make(chan bool, 10) | |
// Launch goroutines | |
for i := 0; i < 10; i++ { | |
go func() { | |
// Generate some random numbers |
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
m := make(map[float64]float64) | |
// Create mutex manually | |
mux := sync.Mutex{} | |
doneChannel := make(chan bool, 10) | |
for i := 0; i < 10; i++ { | |
go func() { | |
for i := 0; i < 1000; i++ { |
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
ExecutorService executor = Executors.newFixedThreadPool(4); | |
for (int i = 0; i < 10; i++) { | |
executor.execute(() -> { | |
//No Java without boilerplate! | |
try { | |
Thread.sleep(1000); | |
} catch (InterruptedException e) {} | |
System.out.println("Finished"); | |
}); | |
} |
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
for i := 0; i < 10; i++ { | |
go func() { | |
time.Sleep(1 * time.Second) | |
fmt.Println("Finished") | |
}() | |
} |
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
wg := sync.WaitGroup{} | |
// Wait for all child goroutines | |
wg.Add(10) | |
for i := 0; i < 10; i++ { | |
go func(wg sync.WaitGroup) { | |
time.Sleep(1 * time.Second) | |
fmt.Println("Finished") | |
wg.Done() | |
}(wg) | |
} |
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
wg := &sync.WaitGroup{} | |
wg.Add(10) | |
for i := 0; i < 10; i++ { | |
go func(wg *sync.WaitGroup) { | |
time.Sleep(1 * time.Second) | |
fmt.Println("Finished") | |
wg.Done() | |
}(wg) | |
} | |
wg.Wait() |
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
wg := sync.WaitGroup{} | |
for i := 0; i < 10; i++ { | |
wg.Add(1) | |
go func() { | |
time.Sleep(1 * time.Second) | |
fmt.Println("Finished") | |
wg.Done() | |
}() | |
} | |
wg.Wait() |
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
package main | |
import ( | |
"fmt" | |
"unicode/utf8" | |
) | |
func main() { | |
word := `Maximilianstraße` |
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
@SpringBootApplication | |
class KotlinSpringBootApplication | |
fun main(args: Array<String>) { | |
// That part of boilerplate you still cannot get rid of | |
SpringApplication.run(KotlinSpringBootApplication::class.java, *args) | |
} |
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
// No need for setters getters for a simple POJO | |
data class Cat(var id : UUID? = null, | |
val name: String, | |
val age: Float, | |
val weight: Float, | |
var sex : Cat.Sex = Sex.Unknown) { | |
enum class Sex { | |
Unknown, | |
Male, | |
Female, |
OlderNewer