# Struct futures::sync::BiLock [−] [src]

    pub struct BiLock<T> { /* fields omitted */ }

A type of futures-powered synchronization primitive which is a mutex between two possible owners.

This primitive is not as generic as a full-blown mutex but is sufficient for many use cases where there are only two possible owners of a resource. The implementation of `BiLock` can be more optimized for just the two possible owners.

Note that it's possible to use this lock through a poll-style interface with the `poll_lock` method but you can also use it as a future with the `lock` method that consumes a `BiLock` and returns a future that will resolve when it's locked.

A `BiLock` is typically used for "split" operations where data which serves two purposes wants to be split into two to be worked with separately. For example a TCP stream could be both a reader and a writer or a framing layer could be both a stream and a sink for messages. A `BiLock` enables splitting these two and then using each independently in a futures-powered fashion.

## Methods

### `impl<T> BiLock<T>`
[src]

#### `pub fn new(t: T) -> (BiLock<T>, BiLock<T>)`
[src]

Creates a new `BiLock` protecting the provided data.

Two handles to the lock are returned, and these are the only two handles that will ever be available to the lock. These can then be sent to separate tasks to be managed there.

#### `pub fn poll_lock(&self) -> Async<BiLockGuard<T>>`
[src]

Attempt to acquire this lock, returning `NotReady` if it can't be acquired.

This function will acquire the lock in a nonblocking fashion, returning immediately if the lock is already held. If the lock is successfully acquired then `Async::Ready` is returned with a value that represents the locked value (and can be used to access the protected data). The lock is unlocked when the returned `BiLockGuard` is dropped.

If the lock is already held then this function will return `Async::NotReady`. In this case the current task will also be scheduled to receive a notification when the lock would otherwise become available.

# Panics

This function will panic if called outside the context of a future's task.

#### `pub fn lock(self) -> BiLockAcquire<T>`
[src]

Perform a "blocking lock" of this lock, consuming this lock handle and returning a future to the acquired lock.

This function consumes the `BiLock<T>` and returns a sentinel future, `BiLockAcquire<T>`. The returned future will resolve to `BiLockAcquired<T>` which represents a locked lock similarly to `BiLockGuard<T>`.

Note that the returned future will never resolve to an error.

#### `pub fn reunite(self, other: Self) -> Result<T, ReuniteError<T>>`
[src]

Attempts to put the two "halves" of a `BiLock<T>` back together and recover the original value. Succeeds only if the two `BiLock<T>`s originated from the same call to `BiLock::new`.

## Trait Implementations

### `impl<T: Debug> Debug for BiLock<T>`
[src]

#### `fn fmt(&self, __arg_0: &mut Formatter) -> Result`
[src]

Formats the value using the given formatter. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)