question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrapper Classes should be frozen on create

See original GitHub issue

If we freeze the wrapper classes after creation, we can then safely pass those around between iOS threads.

Simple example in pseudo swift code:

this will work as both the creation and the call happen on the main thread

THREAD:MAIN {
   let loadUserUseCaseIos = LoadUserUseCaseIos(LoadUserUseCase(...))
  
   loadUserUseCaseIos.loadUser(username: "foo").subscribe(
              scope: coroutineScope, //this can be provided automatically, more on that below
              onSuccess: { user in print(user?.description() ?? "none") },
              onThrow: { error in print(error.description())}
          )
}

this will FAIL as the creation happens on another thread than the call

THREAD:MAIN {
   let loadUserUseCaseIos = LoadUserUseCaseIos(LoadUserUseCase(...))
}
THREAD:IO {
   loadUserUseCaseIos.loadUser(username: "foo").subscribe(
              scope: coroutineScope, //this can be provided automatically, more on that below
              onSuccess: { user in print(user?.description() ?? "none") },
              onThrow: { error in print(error.description())}
          )
}

But if we freeze the LoadUserUseCaseIos after creation, both will work fine. https://kotlinlang.org/docs/mobile/concurrency-overview.html#immutable-and-frozen-state

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

0reactions
JohNancommented, Aug 2, 2021

I just looked through the repo by @russhwolf and he created 4 wrappers to be able to handle nullable and non-null data. I still think this is a good idea and would make the swift side of the code easier to work with. At least it would be up to the consumer of the library to choose and not forced.

https://github.com/touchlab/SwiftCoroutines

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create custom errors in a wrapper class
I am using wrapper classes to add/ create new records for the 2 child objects on the page. Each action and issue added...
Read more >
Jackson - Wrap POJO in a wrapper class with metadata
The issue is it seems to get stuck in a loop. Constantly trying to serialise the model, nesting within it self. I've tried...
Read more >
Object.freeze() - JavaScript - MDN Web Docs
To make an object immutable, recursively freeze each non-primitive property (deep freeze). Use the pattern on a case-by-case basis based on your ...
Read more >
Wrapper Classes in Java - GeeksforGeeks
A Wrapper class is a class whose object wraps or contains primitive data types. When we create an object to a wrapper class,...
Read more >
Attributes — The Swift Programming Language (Swift 5.7)
Apply this attribute to a class, structure, enumeration, or protocol to treat ... Dynamic member lookup by member name can be used to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found