title: What is the best way to poll for messages from Amazon Web Services SQS
body: <p>What is the best way to poll for messages from Amazon Web Services SQS? I want to handle the messages as soon as they are in the queue and don't really want to poll every second unless this is the only option?</p>
  <p><code>setInterval(run(), 1000);</code> I get the error</p>
  <pre><code>const run: () =&gt; Promise&lt;void&gt;
  //---------------------------------
  No overload matches this call.
    Overload 1 of 2, '(callback: (...args: any[]) =&gt; void, ms: number, ...args: any[]): Timeout', gave the following error.
      Argument of type 'Promise&lt;void&gt;' is not assignable to parameter of type '(...args: any[]) =&gt; void'.
        Type 'Promise&lt;void&gt;' provides no match for the signature '(...args: any[]): void'.
    Overload 2 of 2, '(handler: TimerHandler, timeout?: number, ...arguments: any[]): number', gave the following error.
      Argument of type 'Promise&lt;void&gt;' is not assignable to parameter of type 'TimerHandler'.
        Type 'Promise&lt;void&gt;' is missing the following properties from type 'Function': apply, call, bind, prototype, and 5 more.ts(2769)`
  </code></pre>
  <p>my code...</p>
  <pre><code>const QueueUrl = process.env.SQS_QUEUE_URL;
  const params = {
    AttributeNames: ['SentTimestamp'],
    MaxNumberOfMessages: 10,
    MessageAttributeNames: ['All'],
    QueueUrl,
    VisibilityTimeout: 20,
    WaitTimeSeconds: 0,
  };
  const sqs = new SQSClient({ region: process.env.SQS_REGION });
  
  const run = async () =&gt; {
    try {
      const data = await sqs.send(new ReceiveMessageCommand(params));
      if (data.Messages) {
        for (const val of data.Messages) {
          const address = val.MessageAttributes.Address.StringValue;
          const amount = Number(val.MessageAttributes.Amount.StringValue);
          createTransaction(address, amount);
          const deleteParams = {
            QueueUrl,
            ReceiptHandle: val.ReceiptHandle,
          };
          try {
            await sqs.send(new DeleteMessageCommand(deleteParams));
          } catch (err) {
            // tslint:disable-next-line: no-console
            console.log('Message Deleted', data);
          }
        }
      } else {
        // tslint:disable-next-line: no-console
        console.log('No messages to delete');
      }
    } catch (err) {
      // tslint:disable-next-line: no-console
      console.log('Receive Error', err);
    }
  };
  run();
  </code></pre>