protected virtual void OnJobNotificationReceived(UvAsync async) { var loopsRemaining = MaxLoops; bool wasWork; do { wasWork = this.DoWork(); loopsRemaining--; }while (wasWork && loopsRemaining > 0); }
private void ThreadStart(object state) { var tcs = (TaskCompletionSource <int>)state; try { this.uvLoop = new UvLoop(); this.jobNotificationAsync = new UvAsync(this.uvLoop, this.OnJobNotificationReceived); this.uvLoop.Run(UvLoopRunMode.RunNowait); // Test run tcs.SetResult(0); } catch (Exception exception) { tcs.SetException(exception); return; } try { try { this.uvLoop.Run(); } catch (Exception exception) { this.OnLoopError(exception); } try { this.jobNotificationAsync.Close(); this.uvLoop.Run(UvLoopRunMode.RunNowait); // Run one more time to close all handles left this.uvLoop.Close(); } catch (Exception exception) { this.OnLoopError(exception); } } finally { this.threadTcs.SetResult(null); } }
public void AsyncCallbackTet() { var callbackCallCount = 0; var loop = new UvLoop(); var async = new UvAsync(loop, thisAsync => { callbackCallCount++; thisAsync.Close(); }); Assert.Equal(0, callbackCallCount); loop.Run(UvLoopRunMode.RunNowait); Assert.Equal(0, callbackCallCount); new Thread(() => { async.Send(); }).Start(); Assert.Equal(0, callbackCallCount); loop.Run(); loop.Close(); Assert.Equal(1, callbackCallCount); }
public static extern int uv_async_send(UvAsync handle);
public static extern int uv_async_init(UvLoop loop, UvAsync handle, UvAsyncCallback cb);