# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pollz.gitbook.io/pollz/api-reference/polls/listen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
