> For the complete documentation index, see [llms.txt](https://pollz.gitbook.io/pollz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pollz.gitbook.io/pollz/api-reference/polls/listen.md).

# listen()

**`listen(pollId: EntryIdType, callback: (poll: PollWithOptions) => void, orderOptionsBy = OrderBy.Asc): () => void`**

Set up a real-time listener for updates to a specific poll.

**Parameters:**

* `pollId` (EntryIdType): The ID of the poll for which to listen to updates.
* `callback` ((poll: PollWithOptions) => void): A callback function that will be invoked when the poll is updated. It receives the updated poll object as its parameter.
* `orderOptionsBy` (OrderBy, optional): The order in which to retrieve poll options for the updated poll. Default is `OrderBy.Asc` (ascending).

**Returns:**

* A function that can be called to stop listening to updates for the specified poll.

**Example:**

```javascript
const pollIdToListen = 1;

const unsubscribe = pollz.polls.listen(pollIdToListen, (updatedPoll) => {
  console.log('Poll Updated:', updatedPoll);
});

// To stop listening
// unsubscribe();
```

The `listen` method enables you to set up a real-time listener for updates to a specific poll identified by its unique ID (`pollId`). Provide a callback function (`callback`) that will be invoked each time the poll is updated. The callback receives the updated poll object (`PollWithOptions`) as its parameter.

The method returns a function (`unsubscribe`) that can be called to stop listening to updates for the specified poll. Call `unsubscribe` when you no longer need to receive updates.

**Note:** Ensure that the provided `pollId` corresponds to an existing poll in the system.
