Skip to content

Commit

Permalink
feat: add polling interval to polling transport
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Jun 15, 2021
1 parent a648cad commit f7200e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/getting-started/1-transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const agentConfig = {

const agent = new Agent(agentConfig)

const pollingInboundTransporter = new PollingInboundTransporter()
// Construct polling inbound transporter with optional polling interval in ms
const pollingInboundTransporter = new PollingInboundTransporter(5000)

agent.setInboundTransporter(pollingInboundTransporter)
```
Expand Down
6 changes: 4 additions & 2 deletions src/transport/PollingInboundTransporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { sleep } from '../utils/sleep'

export class PollingInboundTransporter implements InboundTransporter {
public stop: boolean
private pollingInterval: number

public constructor() {
public constructor(pollingInterval = 5000) {
this.stop = false
this.pollingInterval = pollingInterval
}

public async start(agent: Agent) {
Expand Down Expand Up @@ -41,7 +43,7 @@ export class PollingInboundTransporter implements InboundTransporter {
private async pollDownloadMessages(agent: Agent) {
while (!this.stop) {
await agent.routing.downloadMessages()
await sleep(5000)
await sleep(this.pollingInterval)
}
}
}

0 comments on commit f7200e9

Please sign in to comment.