| 603 | |
| 604 | |
| 605 | bool Pipe::Writer::fail(const string& message) |
| 606 | { |
| 607 | bool failed = false; |
| 608 | queue<Owned<Promise<string>>> reads; |
| 609 | |
| 610 | synchronized (data->lock) { |
| 611 | if (data->writeEnd == Writer::OPEN) { |
| 612 | // Extract all the pending reads so we can fail them. |
| 613 | std::swap(data->reads, reads); |
| 614 | |
| 615 | data->writeEnd = Writer::FAILED; |
| 616 | data->failure = Failure(message); |
| 617 | failed = true; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | // NOTE: We set the promises outside the critical section to avoid |
| 622 | // triggering callbacks that try to reacquire the lock. |
| 623 | while (!reads.empty()) { |
| 624 | reads.front()->fail(message); |
| 625 | reads.pop(); |
| 626 | } |
| 627 | |
| 628 | return failed; |
| 629 | } |
| 630 | |
| 631 | |
| 632 | Future<Nothing> Pipe::Writer::readerClosed() const |
no test coverage detected