This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WallFragment : Fragment() { | |
| private lateinit var itemSelector: Selector | |
| private lateinit var model: SharedViewModel | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| model = activity?.run { | |
| ViewModelProviders.of(this).get(SharedViewModel::class.java) | |
| } ?: throw Exception("Invalid Activity") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class WallDetailFragment : Fragment() { | |
| private lateinit var model: SharedViewModel | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| model = activity?.run { | |
| ViewModelProviders.of(this).get(SharedViewModel::class.java) | |
| } ?: throw Exception("Invalid Activity") | |
| model.data.observe(this, Observer<Item> { item -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MainActivity: AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| val viewModel = ViewModelProviders.of(this).get(SharedViewModel::class.java) | |
| viewModel.data.observe(this, Observer { | |
| }) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func generateMessage(message string) { | |
| // Buffered Channel of type Boolean | |
| done := make(chan bool, 1) | |
| go printMessage(done, message) | |
| // Waiting to receive value from channel | |
| <-done | |
| } | |
| func printMessage(done chan bool, message string) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mutex = &sync.Mutex{} | |
| var wg sync.WaitGroup | |
| func generateMessage(message string) { | |
| //... | |
| wg.Add(1) | |
| go func() { | |
| defer wg.Done() | |
| printMessage(message) |
OlderNewer