Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

15278 detekt rule runblocking #15942

Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
266786b
For #15278: added CoroutineManager to count runBlocking calls
MarcLeclair Oct 7, 2020
da7b1ed
For #15278: Added actual detekt rule for runblocking and its config t…
MarcLeclair Oct 15, 2020
1214bb6
For #15278: Added unit test for RunblockingCounter
MarcLeclair Oct 15, 2020
3fd69e2
For #15278: renamed StrictModeStartupSuppressionCountTest.kt to Perfo…
MarcLeclair Oct 15, 2020
d526980
Lint fix
MarcLeclair Oct 15, 2020
d1db99f
For #15278: made runblocking a Long to prevent overflow
MarcLeclair Oct 15, 2020
5f1c747
For #15278: fixed MozRunblocking name, description and moved RunBlock…
MarcLeclair Oct 20, 2020
c277469
For #15278:Renamed MozillaRunblockingCheck to MozillaRunBlockingCheck
MarcLeclair Oct 20, 2020
de6a96d
For #15278: Added setup for unit test, since it failed without restti…
MarcLeclair Oct 20, 2020
745e9af
For #15278: Fixed naming for RunBlocking lint check
MarcLeclair Oct 20, 2020
da0f4c6
For #15278: removed changes made to test to use runBlockingIncrement
MarcLeclair Oct 20, 2020
bb5636d
For #15728: added test exclusion for runBlocking check
MarcLeclair Oct 20, 2020
a121a9b
For #15278: changed null check and added Synchronized to count setter
MarcLeclair Oct 20, 2020
8d63ebc
For #15278: fix for nits
MarcLeclair Oct 27, 2020
36fc3e1
For #15278: added StartupExcessiveResourceUseTest to CODEOWNERS
MarcLeclair Oct 28, 2020
676fb6b
For #15278: fixed for nits
MarcLeclair Oct 29, 2020
5f2da80
For #15278: Moved increment function to extension function and fixed …
MarcLeclair Oct 30, 2020
b265a37
For #15278: Added tests for Atomic Integer extension and nit fix
MarcLeclair Nov 2, 2020
e0be45d
merged master
MarcLeclair Nov 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/src/main/java/org/mozilla/fenix/CoroutineManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

/**
* Counts the number of runBlocking calls made
*/
private class RunblockingCounter{
MarcLeclair marked this conversation as resolved.
Show resolved Hide resolved
companion object{
var runBlockingCount = 0
}
}

/**
* Wrapper around `runBlocking`
*/
fun <T> runBlockingCounter(context: CoroutineContext = EmptyCoroutineContext, action: suspend CoroutineScope.() -> T): T {
RunblockingCounter.runBlockingCount += 1
if(context != EmptyCoroutineContext){
return runBlocking(context) { action()}
}
return runBlocking { action() }
}