@@ -99,83 +99,3 @@ fun Document.extractChangelog(id: String) = this
9999    .takeWhile  { it.`is `(" :not(h2)"  ) }
100100    .takeWhile  { it.`is `(" :not(h3)"  ) }
101101    .joinToString(" \n "  )
102- 
103- 
104- 
105- /*  -------------------------------------------------------------------------- */ 
106- /*  -------------------------------------------------------------------------- */ 
107- /*  -------------------------------------------------------------------------- */ 
108- /*  -------------------------------------------------------------------------- */ 
109- /*  -------------------------------------------------------------------------- */ 
110- 
111- 
112- 
113- //  This is a coroutine version of the code.
114- //  Needs @file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1")
115- //  which seems to not work in Kotlin scripts.
116- //  Probably fixed in Kotlin 1.7 or newer
117- /* 
118- fun main() = runBlocking { 
119-     val init = async(Dispatchers.IO) { 
120-         flow { 
121-             emit(XmlReader(javaClass.getResource("/test-feed-result.xml"))) 
122-             // emit(XmlReader(feedUrl)) 
123-         }.retry(10) { 
124-             println("Failed to create the reader. Retrying in $waitTime...") 
125-             delay(waitTime.inWholeMilliseconds) 
126-             it is Exception 
127-         }.single() 
128-     } 
129-     val reader = init.await() 
130-     val feed = SyndFeedInput().build(reader) 
131-     val latestRelease = feed.entries.first() 
132-     val latestReleaseItems = latestRelease.contents.first().value 
133- 
134-     var totalItems = 0 
135-     var processed = 0.0 
136- 
137-     // See https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/collect.html 
138-     val job = launch(Dispatchers.IO) { 
139-         Jsoup 
140-             .parse(latestReleaseItems) 
141-             .select("a") 
142-             .also { totalItems = it.size } 
143-             .asFlow() 
144-             .onStart { println("Downloading items started...") } 
145-             .map(::toLink) 
146-             // Make toDocument and tryTo suspendable and use delay in tryTo? 
147-             // See https://stackoverflow.com/a/46890009 
148-             .map(::toDocument) 
149-             // .catch {  } 
150-             // NOTE that retry will start the whole flow over again. 
151-             .retry(5) { 
152-                 println("Some error happened. Starting over in $waitTime...") 
153-                 delay(waitTime.inWholeMilliseconds) 
154-                 it is Exception 
155-             } 
156-             .onEach { processed++ } 
157-             .onEach { println("Successful download: ${it.first}") } 
158-             .map(::toReleaseNote) 
159-             // .flowOn(Dispatchers.IO) 
160-             .onEmpty { emit("No libraries entries!") } 
161-             .onEach(writer::write) 
162-             .onCompletion { println("All items downloaded.") } 
163-             .collect() 
164-             .also { writer.close() } 
165-             .also { reader.close() } 
166-     } 
167- 
168-     var previousProgress = -1 
169-     while (!job.isCompleted) { 
170-         delay(100) 
171-         val progress = (processed / totalItems * 100).roundToInt() 
172-         if (progress != previousProgress) println("Progress: $progress%") 
173-         previousProgress = progress 
174-         // yield() 
175-     } 
176- 
177-     // Create a raw text version as well just if someone needs it 
178-     val text = Jsoup.parse(resultFile, null).wholeText() 
179-     File("release-notes.txt").writeText(text) 
180- } 
181- */ 
0 commit comments