Update changelog for 0.4.0
[osm/N2VC.git] / examples / allwatcher.py
index ecd6e82..c78d689 100644 (file)
@@ -11,19 +11,21 @@ import asyncio
 import logging
 
 from juju.client.connection import Connection
-from juju.client import watcher
+from juju.client import client
+from juju import loop
 
 
 async def watch():
-    allwatcher = watcher.AllWatcher()
-    allwatcher.connect(conn)
+    conn = await Connection.connect_current()
+    allwatcher = client.AllWatcherFacade.from_connection(conn)
     while True:
         change = await allwatcher.Next()
         for delta in change.deltas:
             print(delta.deltas)
 
 
-logging.basicConfig(level=logging.DEBUG)
-loop = asyncio.get_event_loop()
-conn = loop.run_until_complete(Connection.connect_current())
-loop.run_until_complete(watch())
+if __name__ == '__main__':
+    logging.basicConfig(level=logging.DEBUG)
+    # Run loop until the process is manually stopped (watch will loop
+    # forever).
+    loop.run(watch())