fix a bug in the way we poll for completion of invocations (#17)

diff --git a/client/lib/activations.js b/client/lib/activations.js
index 4e9f4ae..ad019ba 100644
--- a/client/lib/activations.js
+++ b/client/lib/activations.js
@@ -76,18 +76,26 @@
 	    }).catch(errorWhile('listing activations', reject));
 	};
 
-	//
-	// start up the poller. we first need to fetch the most recent "since"
-	//
+	var since = options.since || Date.now();
+	setTimeout(() => pollOnce(since), pollIntervalMillis);
+    });
+};
+
+exports.mostRecentEnd = wskprops => {
+    return new Promise((resolve, reject) => {
+	var key = wskprops.AUTH;
+	var ow = openwhisk({
+	    api: api.host + api.path,
+	    api_key: key,
+	    namespace: '_' // special here, as activations are currently stored in the user's default namespace
+	});
+
 	ow.activations.list({ limit: 1, docs: true }).then(lastOne => {
 	    //
 	    // if no activations were found, then use "now"
 	    //
-	    var since = !lastOne
-		? options.since || Date.now()
-		: lastOne[0].end;
-
-	    setTimeout(() => pollOnce(since), pollIntervalMillis);
-	});
+	    resolve(lastOne[0].end || Date.now());
+	}).catch(reject);
     });
 };
+   
diff --git a/client/lib/rewriter.js b/client/lib/rewriter.js
index 702e22a..7fd6c01 100644
--- a/client/lib/rewriter.js
+++ b/client/lib/rewriter.js
@@ -20,6 +20,7 @@
     inquirer = require('inquirer'),
     openwhisk = require('openwhisk'),
     setupOpenWhisk = require('./util').setupOpenWhisk,
+    mostRecentEnd = require('./activations').mostRecentEnd,
     waitForActivationCompletion = require('./activations').waitForActivationCompletion,
     lister = require('./commands/list'),
     Namer = require('./namer'),
@@ -610,10 +611,9 @@
     // remember the time, so that the waitForActivationCompletion
     // doesn't look for previous invocations of the given action
     //
-    var now = Date.now();
-    
-    ow.actions.invoke({ actionName: invokeThisAction, params: params })
-	.then(() => waitForActivationCompletion(wskprops, eventBus, waitForThisAction, { result: true, since: now })
-	      .then(ok(next)))
-	.catch(errorWhile('invoking your specified action', next));
+    mostRecentEnd(wskprops)
+	.then(since => ow.actions.invoke({ actionName: invokeThisAction, params: params })
+	      .then(() => waitForActivationCompletion(wskprops, eventBus, waitForThisAction, { result: true, since: since })
+		    .then(ok(next)))
+	      .catch(errorWhile('invoking your specified action', next)));
 };