|
519 | 519 | Determines whether a [`Channel`](@ref) has a value stored in it. |
520 | 520 | Returns immediately, does not block. |
521 | 521 |
|
522 | | -For unbuffered channels returns `true` if there are tasks waiting on a [`put!`](@ref). |
| 522 | +For unbuffered channels, return `true` if there are tasks waiting on a [`put!`](@ref). |
523 | 523 |
|
524 | 524 | # Examples |
525 | 525 |
|
@@ -559,6 +559,47 @@ function n_avail(c::Channel) |
559 | 559 | @atomic :monotonic c.n_avail_items |
560 | 560 | end |
561 | 561 |
|
| 562 | +""" |
| 563 | + isfull(c::Channel) |
| 564 | +
|
| 565 | +Determines if a [`Channel`](@ref) is full, in the sense |
| 566 | +that calling `put!(c, some_value)` would have blocked. |
| 567 | +Returns immediately, does not block. |
| 568 | +
|
| 569 | +Note that it may frequently be the case that `put!` will |
| 570 | +not block after this returns `true`. Users must take |
| 571 | +precautions not to accidentally create live-lock bugs |
| 572 | +in their code by calling this method, as these are |
| 573 | +generally harder to debug than deadlocks. It is also |
| 574 | +possible that `put!` will block after this call |
| 575 | +returns `false`, if there are multiple producer |
| 576 | +tasks calling `put!` in parallel. |
| 577 | +
|
| 578 | +# Examples |
| 579 | +
|
| 580 | +Buffered channel: |
| 581 | +```jldoctest |
| 582 | +julia> c = Channel(1); # capacity = 1 |
| 583 | +
|
| 584 | +julia> isfull(c) |
| 585 | +false |
| 586 | +
|
| 587 | +julia> put!(c, 1); |
| 588 | +
|
| 589 | +julia> isfull(c) |
| 590 | +true |
| 591 | +``` |
| 592 | +
|
| 593 | +Unbuffered channel: |
| 594 | +```jldoctest |
| 595 | +julia> c = Channel(); # capacity = 0 |
| 596 | +
|
| 597 | +julia> isfull(c) # unbuffered channel is always full |
| 598 | +true |
| 599 | +``` |
| 600 | +""" |
| 601 | +isfull(c::Channel) = n_avail(c) ≥ c.sz_max |
| 602 | + |
562 | 603 | lock(c::Channel) = lock(c.cond_take) |
563 | 604 | lock(f, c::Channel) = lock(f, c.cond_take) |
564 | 605 | unlock(c::Channel) = unlock(c.cond_take) |
|
0 commit comments