| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dff01d1 commit 8872840
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,23 +5,25 @@ const assert = require('assert'); | |||
| 5 | 5 | const dgram = require('dgram'); | |
| 6 | 6 | const client = dgram.createSocket('udp4'); | |
| 7 | 7 | const chunk = 'abc'; | |
| 8 | - var recursiveCount = 0; | ||
| 9 | - var received = 0; | ||
| 8 | + let received = 0; | ||
| 9 | + let sent = 0; | ||
| 10 | 10 | const limit = 10; | |
| 11 | - const recursiveLimit = 100; | ||
| 11 | + let async = false; | ||
| 12 | 12 | ||
| 13 | 13 | function onsend() { | |
| 14 | - if (recursiveCount > recursiveLimit) { | ||
| 15 | - throw new Error('infinite loop detected'); | ||
| 16 | - } | ||
| 17 | - if (received < limit) { | ||
| 14 | + if (sent++ < limit) { | ||
| 18 | 15 | client.send( | |
| 19 | 16 | chunk, 0, chunk.length, common.PORT, common.localhostIPv4, onsend); | |
| 17 | + } else { | ||
| 18 | + assert.strictEqual(async, true, 'Send should be asynchronous.'); | ||
| 20 | 19 | } | |
| 21 | - recursiveCount++; | ||
| 22 | 20 | } | |
| 23 | 21 | ||
| 24 | 22 | client.on('listening', function() { | |
| 23 | + setImmediate(function() { | ||
| 24 | + async = true; | ||
| 25 | + }); | ||
| 26 | + | ||
| 25 | 27 | onsend(); | |
| 26 | 28 | }); | |
| 27 | 29 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments