From 930ef2363eb53e76ce158d38532b3ab14ea82bfc Mon Sep 17 00:00:00 2001 From: Luca Tassinari Date: Wed, 10 Jan 2024 12:45:27 +0100 Subject: [PATCH] fix: use main method instead of obejct --- .../tassiLuca/gears/posts/UsePostsApp.scala | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/scala/io/github/tassiLuca/gears/posts/UsePostsApp.scala b/src/main/scala/io/github/tassiLuca/gears/posts/UsePostsApp.scala index 584d5f24..e9ef6b04 100644 --- a/src/main/scala/io/github/tassiLuca/gears/posts/UsePostsApp.scala +++ b/src/main/scala/io/github/tassiLuca/gears/posts/UsePostsApp.scala @@ -3,19 +3,20 @@ package io.github.tassiLuca.gears.posts import gears.async.{Async, Future} import gears.async.default.given -object UsePostsApp extends App: +/* TODO WARNING: USING AN OBJECT WHICH EXTENDS `App` CAUSES STARVATION! + * THE WORKER THREAD GETS STUCK WAITING FOR THE RELEASE OF THE MONITOR LOCK + * waiting on the Class initialization monitor for io.github.tassiLuca.gears.posts.UsePostsApp$ + * TO BE INVESTIGATED! */ +@main def usePostsApp(): Unit = val app = BlogPostsApp Async.blocking: - val f = Future: - println("POST 1") + val f1 = Future: + println(s"POST 1 carried by ${Thread.currentThread()}") app.postsService.create("ltassi@gmail.com", "A hello world post", "Hello World!") - // println(app.postsService.get("A hello world post")) -// val f2 = Future: -// println("POST 2") -// app.postsService.create("ltassi@gmail.com", "An another post", "Hello World 2!") -// println(app.postsService.get("An another post")) -// f1.await -// f2.await - println("End of the world...") - f.await - println("Ok") + println(app.postsService.get("A hello world post")) + val f2 = Future: + println(s"POST 2 carried by ${Thread.currentThread()}") + app.postsService.create("ltassi@gmail.com", "An another post", "Hello World 2!") + println(app.postsService.get("An another post")) + f1.await + f2.await