chvanikoff / apns4ex

APNS for Elixir
MIT License
70 stars 23 forks source link

Add push_async function #36

Closed ramhoj closed 8 years ago

ramhoj commented 8 years ago

Currently push messages are sent one by one even if there are many workers configured in the pool.

It might not be a good idea to just wrap APNS.push/2 in Task.async/1 but having this as a separate function would make it clearer that this is a choice the consumer can do.

An even fancier version of this would be to have a push_many function that process tokens in chunks and runs x push-calls in parallel but so that there is a cap on how many processes is spawned.

pseudo example:

Enum.chunk(tokens, 100, fn (chunk) ->
  jobs = for token <- chunk do
    Task.async(fn->
      APNS.push(pool, message)
    end)

   await_many(jobs)
  end
end)