Skip to content

Instantly share code, notes, and snippets.

View YashishDua's full-sized avatar

Yashish Dua YashishDua

View GitHub Profile
var mutex = &sync.Mutex{}
var wg sync.WaitGroup
func generateMessage(message string) {
//...
wg.Add(1)
go func() {
defer wg.Done()
printMessage(message)
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) {
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 {
})
}
}
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 ->
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")
class SharedViewModel : ViewModel() {
val data = MutableLiveData<Item>()
fun data(item: Item) {
data.value = item
}
}
interface FragmentListener {
fun handleOnClick()
}
class MainActivity : AppCompatActivity(), FragmentListener {
// ...
override fun handleOnClick() {
// Action to implement
}
}
class WallFragment : Fragment() {
companion object {
fun newInstance() = WallFragment()
}
private lateinit var fragmentListener: FragmentListener
override fun onAttach(context: Context?) {
super.onAttach(context)
#FF4336
#9727BO
#673AB7