Skip to content

Commit

Permalink
Merge pull request #49 from arrow-kt/sv-watchPaths
Browse files Browse the repository at this point in the history
Add watchPaths, and fix auto-reload. Update docs
  • Loading branch information
nomisRev authored Jan 23, 2023
2 parents 9caa24a + 1816af7 commit bc49629
Show file tree
Hide file tree
Showing 38 changed files with 896 additions and 203 deletions.
23 changes: 12 additions & 11 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ then it will run all the `suspend finalizers` before closing the `App`.

```kotlin
fun main() = SuspendApp {
Resource(
acquire = { println("Creating some resource") },
release = { _, exitCase ->
resourceScope {
install({ println("Creating some resource") }) { _, exitCase ->
println("ExitCase: $exitCase")
println("Shutting down will take 10 seconds")
delay(10_000)
println("Shutdown finished")
}
).use {
println("Application running with acquired resources.")
awaitCancellation()
}
Expand Down Expand Up @@ -121,7 +119,8 @@ More information on this can be found in this blog by [Phil Pearl](https://philp
and on [learnk8s.io](https://learnk8s.io/graceful-shutdown).

The module `suspendapp-ktor` provides a `server` constructor that lifts the Ktor `ApplicationEngine` in to a `Resource`,
representing the _Engine_ running an `Application`(i.e `Netty`).
representing the _Engine_ running an `Application`(i.e `Netty`) while supporting auto-reload.
Check the official Ktor documentation to learn more about [watchPaths](https://ktor.io/docs/auto-reload.html).

When our `release` function of our `ApplicationEngine` is called, there is a `wait` period before the beginning of the stop
process (defaulted to `30.seconds`), this gives Kubernetes enough time to do all its network management before we shut down.
Expand All @@ -134,14 +133,16 @@ a `SuspendApp`.

```kotlin
fun main() = SuspendApp {
resource {
val engine = server(Netty).bind()
engine.application.routing {
get("/ping") {
call.respond("pong")
resourceScope {
server(Netty) {
routing {
get("/ping") {
call.respond("pong")
}
}
}
}.use { awaitCancellation() }
awaitCancellation()
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.coroutines)
api(libs.coroutines)
}
}

Expand Down
22 changes: 22 additions & 0 deletions docs/images/nav-icons/abstract-class-kotlin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/images/nav-icons/abstract-class.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/images/nav-icons/annotation-kotlin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/annotation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/images/nav-icons/class-kotlin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/class.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/images/nav-icons/enum-kotlin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/enum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/exception-class.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/images/nav-icons/field-value.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/images/nav-icons/field-variable.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/function.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/images/nav-icons/interface-kotlin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/images/nav-icons/interface.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions docs/images/nav-icons/object.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 17 additions & 8 deletions docs/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="sideMenuPart" id="suspendapp-nav-submenu-0" pageId="suspendapp::arrow.continuations////PointingToDeclaration//788909594">
<div class="overview"><span class="navButton" onclick="document.getElementById(&quot;suspendapp-nav-submenu-0&quot;).classList.toggle(&quot;hidden&quot;);"><span class="navButtonContent"></span></span><a href="suspendapp/arrow.continuations/index.html"><span>arrow.</span><wbr></wbr><span><span>continuations</span></span></a></div>
<div class="sideMenuPart" id="suspendapp-nav-submenu-0-0" pageId="suspendapp::arrow.continuations//SuspendApp/#kotlin.coroutines.CoroutineContext#kotlin.time.Duration#kotlin.coroutines.SuspendFunction1[kotlinx.coroutines.CoroutineScope,kotlin.Unit]/PointingToDeclaration//788909594">
<div class="overview"><a href="suspendapp/arrow.continuations/-suspend-app.html"><span>Suspend</span><wbr></wbr><span><span>App()</span></span></a></div>
<div class="overview"><a href="suspendapp/arrow.continuations/-suspend-app.html"><span class="nav-link-grid"><span class="nav-link-child nav-icon function"></span><span class="nav-link-child"><span>Suspend</span><wbr></wbr><span><span>App()</span></span></span></span></a></div>
</div>
</div>
<div class="sideMenuPart" id="suspendapp-nav-submenu-1" pageId="suspendapp::arrow.continuations.unsafe////PointingToDeclaration//337714522">
Expand Down
10 changes: 5 additions & 5 deletions docs/scripts/main.js

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion docs/scripts/navigation-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ displayNavigationFromPage = () => {
})
}).then(() => {
revealNavigationForCurrentPage()
}).then(() => {
scrollNavigationToSelectedElement()
})
document.querySelectorAll('.footer a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
Expand Down Expand Up @@ -51,6 +53,31 @@ revealParents = (part) => {
}
};

scrollNavigationToSelectedElement = () => {
let selectedElement = document.querySelector('div.sideMenuPart[data-active]')
if (selectedElement == null) { // nothing selected, probably just the main page opened
return
}

let hasIcon = selectedElement.querySelectorAll(":scope > div.overview span.nav-icon").length > 0

// for instance enums also have children and are expandable, but are not package/module elements
let isPackageElement = selectedElement.children.length > 1 && !hasIcon
if (isPackageElement) {
// if package is selected or linked, it makes sense to align it to top
// so that you can see all the members it contains
selectedElement.scrollIntoView(true)
} else {
// if a member within a package is linked, it makes sense to center it since it,
// this should make it easier to look at surrounding members
selectedElement.scrollIntoView({
behavior: 'auto',
block: 'center',
inline: 'center'
})
}
}

/*
This is a work-around for safari being IE of our times.
It doesn't fire a DOMContentLoaded, presumabely because eventListener is added after it wants to do it
Expand All @@ -61,4 +88,4 @@ if (document.readyState == 'loading') {
})
} else {
displayNavigationFromPage()
}
}
Loading

0 comments on commit bc49629

Please sign in to comment.