Add MainLoop API. add an example how to use it.