This file contains 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) |
This file contains 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 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 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 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 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
interface FragmentListener { | |
fun handleOnClick() | |
} |
This file contains 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(), FragmentListener { | |
// ... | |
override fun handleOnClick() { | |
// Action to implement | |
} | |
} |
This file contains 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() { | |
companion object { | |
fun newInstance() = WallFragment() | |
} | |
private lateinit var fragmentListener: FragmentListener | |
override fun onAttach(context: Context?) { | |
super.onAttach(context) |
This file contains 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
#FF4336 | |
#9727BO | |
#673AB7 |
NewerOlder