Package org.apache.sling.scripting.sightly.js.impl.async

# Class AsyncContainer

java.lang.Object
org.apache.sling.scripting.sightly.js.impl.async.AsyncContainer

public class AsyncContainer extends Object
Simple container for asynchronously provided values

## Constructor Summary

Constructors
Constructor
Description
`AsyncContainer()`

## Method Summary

Modifier and Type
Method
Description
`void`
`addListener(UnaryCallback unaryCallback)`
Add a listener that will receive the value in this container when it will be filled.
`void`
`complete(Object value)`
Complete this async container with a value
`UnaryCallback`
`createCompletionCallback()`
Create a callback that will complete this container
`Object`
`getResult()`
Get the result of this holder
`boolean`
`isCompleted()`
Check whether the container was completed with a value

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AsyncContainer

public AsyncContainer()

## Method Details

### addListener

public void addListener(UnaryCallback unaryCallback)
Add a listener that will receive the value in this container when it will be filled. If the container already has a value, the callback is called immediately.

Parameters:
  `unaryCallback` - the callback that will receive the result

### getResult

public Object getResult()
Get the result of this holder

Returns:
  the holder result
Throws:
  `NoSuchElementException` - if the result has not yet been set

### isCompleted

public boolean isCompleted()
Check whether the container was completed with a value

Returns:
  the completion status

### complete

public void complete(Object value)
Complete this async container with a value

Parameters:
  `value` - the result value
Throws:
  `IllegalStateException` - if the container has been previously filled

### createCompletionCallback

public UnaryCallback createCompletionCallback()
Create a callback that will complete this container

Returns:
  the completion callback