This is a sample implementation of ajax polling with amplify.request.
This implementation was written with the goal of providing the same exact API for standard ajax requests and ajax polling requests. The idea was to have the only difference be that the success or error callbacks would be invoked multiple times (once for every poll). This implementation of polling is mostly just a wrapper around the existing ajax implementation to reduce the amount of code needed.
The main problem with this implementation is that all of the request messages have the wrong resource ID. For example, if you define an ajax-poll request with a resource ID of "foo" then all of the messages will have a resource ID of "ajax-poll-foo". At first we were unsure if this was even a problem; the user should already know that they are making a request that will poll, but it still seemed wrong to expose this through the resource ID in the messages.
After some more thought, our current thinking is that it's ok for ajax polling to publish messages with a different resource ID or even have a slightly differnet API. Since the user has to know ahead of time that the request will have multiple responses, they will know what to expect even if the API for responses is slightly different. While it's ok to expose the fact that the request has multiple responses, we should still not expose the fact that the request is using ajax polling.
Since there are several request types that can have multiple respones, such as ajax polling, Web Sockets and Server-Sent Events, they should all have a consistent API. We have decided to hold off on an official implementaiton of ajax polling until we have decided what the common API should be for request types that have multiple responses, but we wanted to get this code out in the public to start gathering feedback.