Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Add unsafeLazy to simplify thread unsafe lazy initializations #950

Merged
merged 1 commit into from
Sep 19, 2022

Conversation

Copy link
Owner

@chrisbanes chrisbanes left a comment

Choose a reason for hiding this comment

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

Looks great overall


package app.tivi.extensions

fun <T> unsafeLazy(initializer: () -> T): Lazy<T> = lazy(LazyThreadSafetyMode.NONE, initializer)
Copy link
Owner

Choose a reason for hiding this comment

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

We can make this an inline function too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But also need to add noinline on initializer, should we do?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah sounds good. This function compiles down to what we had previously, just with a nicer API

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Owner

@chrisbanes chrisbanes left a comment

Choose a reason for hiding this comment

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

Thanks!

@chrisbanes chrisbanes enabled auto-merge (rebase) September 19, 2022 16:24
@chrisbanes chrisbanes disabled auto-merge September 19, 2022 16:25
@chrisbanes chrisbanes enabled auto-merge (rebase) September 19, 2022 16:25
@chrisbanes chrisbanes merged commit d44cdaa into chrisbanes:main Sep 19, 2022
@Goooler Goooler deleted the unsafe_lazy branch September 19, 2022 16:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants