Skip to content

Conversation

PecaWolf
Copy link
Contributor

@PecaWolf PecaWolf commented Oct 3, 2025

@PecaWolf PecaWolf self-assigned this Oct 3, 2025
@PecaWolf PecaWolf force-pushed the feature/NEMO-205/architecture_update branch 3 times, most recently from 89da293 to f6e46ab Compare October 6, 2025 11:02
@PecaWolf PecaWolf requested a review from ArwainK October 6, 2025 11:30
@PecaWolf PecaWolf force-pushed the feature/NEMO-205/architecture_update branch 4 times, most recently from 418d84c to 4419ee5 Compare October 8, 2025 09:21
@PecaWolf PecaWolf force-pushed the feature/NEMO-205/architecture_update branch from 4419ee5 to d7dea90 Compare October 8, 2025 12:09

// Then
assertNotNull(sdk)
assertEquals(sdk, TidepoolSDK.getInstance())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this test pass? Not seeing getInstance() in TidepoolSDK?

Copy link

@ArwainK ArwainK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Noting a few known Limitations (To Be Addressed)

  • Token refresh logic not implemented
  • Several data schemas incomplete (marked with TODO)
  • Limited error handling - generic exceptions only
  • No retry logic for network failures
  • Mapping boilerplate could use code generation

private var currentKey = initialKey

/** Flag to prevent concurrent requests */
private var isMakingRequest = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not thread-safe with coroutines


override suspend fun loadNextItems() {
println("Paginator: loadNextItems() called with key: $currentKey, $isMakingRequest $isEndReached")
if (isMakingRequest || isEndReached) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential race condition here: two coroutines can both pass this check. Maybe we use a Mutex solution here? Something like:

private val requestMutex = Mutex()

override suspend fun loadNextItems() {
    if (requestMutex.isLocked || isEndReached) return
    
    requestMutex.withLock {
        if (isEndReached) return@withLock
        
        val result = onRequest(currentKey)
        // ... handle result
    }
}

val users: UserService by lazy { koin.get() }

public fun shutdown() {
stopKoin()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this stop Koin for the entire application?

Can we use Koin's scope management instead of the global instance here?

class TidepoolSDK(
    environment: Environment,
    private val tokenProvider: TokenProvider,
) {
    private val koinApp = koinApplication {
        modules(
            module {
                single<EnvironmentInternal> { environment.toInternal() }
                single<TokenProvider> { tokenProvider }
            },
            domainModule,
            dataModule,
        )
    }
    
    private val koin: Koin = koinApp.koin
    
    val confirmations: ConfirmationService by lazy { koin.get() }
    val data: DataService by lazy { koin.get() }
    val metadata: MetadataService by lazy { koin.get() }
    val users: UserService by lazy { koin.get() }
    
    fun shutdown() {
        koinApp.close()  // Only closes this instance
    }
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants