I'm not familiar with pubnub, but what you're trying to achieve should be as simple as this:
Pubnub pn = new Pubnub(publishKey, subscribeKey, secretKey, cipherKey, enableSSL);
var tcs = new TaskCompletionSource<PubnubResult>();
pn.HereNow("testchannel", res => //doesn't return a Task
{ //response
tcs.SetResult(res);
}, err =>
{ //error response
tcs.SetException(err);
});
// blocking wait here for the result or an error
var res = tcs.Task.Result;
// or: var res = tcs.Task.GetAwaiter().GetResult();
Note that doing asynchronous stuff synchronously is not recommend. You should look at using async/await
, in which case you'd do:
var result = await tcs.Task;