* Read stdin data (returns null if none available)
()
| 315 | * Read stdin data (returns null if none available) |
| 316 | */ |
| 317 | readStdin() { |
| 318 | if (Atomics.load(this.int32, STDIN_FLAG_INDEX) === 0) { |
| 319 | return null; |
| 320 | } |
| 321 | |
| 322 | const size = Atomics.load(this.int32, STDIN_SIZE_INDEX); |
| 323 | const data = this.uint8.slice(STDIN_OFFSET, STDIN_OFFSET + size); |
| 324 | |
| 325 | // Clear flag and notify writer |
| 326 | Atomics.store(this.int32, STDIN_SIZE_INDEX, 0); |
| 327 | Atomics.store(this.int32, STDIN_FLAG_INDEX, 0); |
| 328 | Atomics.notify(this.int32, STDIN_FLAG_INDEX); |
| 329 | |
| 330 | return data; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Read next network message (returns null if none available) |