Skip to content

Commit

Permalink
Added the ability to cancel the execution of the queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysinyavsky committed Dec 20, 2022
1 parent 9be4107 commit c5578b9
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 14 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ Queue: `check_connection->request_idfa->init->load_rewarded`

- callback <kbd>function</kbd> _optional_ callback with [response](#response)

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.show_rewarded(callback)`

Shows rewarded ads for next network. Callback contain a special `code` field with [events.C_SKIPPED](#response-codes) if the user skipped the ad.
Expand All @@ -247,6 +251,10 @@ Queue: `check_connection->request_idfa->init->load_rewarded->show_rewarded`

- callback <kbd>function</kbd> _optional_ callback with [response](#response).

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.load_interstitial(callback)`

Loads interstitial ads for next network.
Expand All @@ -257,6 +265,10 @@ Queue: `check_connection->request_idfa->init->load_interstitial`

- callback <kbd>function</kbd> _optional_ callback with [response](#response)

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.show_interstitial(callback)`

Shows interstitial ads for next network.
Expand All @@ -267,6 +279,10 @@ Queue: `check_connection->request_idfa->init->load_interstitial->show_interstiti

- callback <kbd>function</kbd> _optional_ callback with [response](#response)

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.load_banner(callback)`

Loads banner for for next network.
Expand All @@ -277,6 +293,10 @@ Queue: `check_connection->request_idfa->init->load_banner`

- callback <kbd>function</kbd> _optional_ callback with [response](#response)

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.show_banner(callback)`

Shows setup banner for next network. Hides the previous banner if it was displayed.
Expand All @@ -287,6 +307,10 @@ Queue: `check_connection->request_idfa->init->load_banner->show_banner`

- callback <kbd>function</kbd> _optional_ callback with [response](#response)

**Return**

- id <kbd>integer|nil</kbd> id to cancel execution

### `ads_wrapper.hide_banner(callback)`

Hides setup banner for current network.
Expand Down Expand Up @@ -404,6 +428,15 @@ Default returns for the video mediator

Remove all registered networks

### `ads_wrapper.cancel(id)`

Сancel execution of the next step in the queue.
For example, if you cancel **show_interstitial** while the ad is loading, then it will not be shown.

**Parameters**

- id <kbd>number</kbd> _required_ queue id received from the function

## Constants

Constants are used to set network parameters
Expand Down
30 changes: 24 additions & 6 deletions ads_wrapper/ads_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,60 +229,71 @@ end

---Loads rewarded ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function M.load_rewarded(callback)
if M.is_video_setup() then
mediator.call_next(video_mediator, queues.load_rewarded, callback)
return mediator.call_next(video_mediator, queues.load_rewarded, callback)
else
mediator_error(VIDEO, callback)
end
return nil
end

---Shows rewarded ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function M.show_rewarded(callback)
if M.is_video_setup() then
mediator.call(video_mediator, queues.show_rewarded, callback)
return mediator.call(video_mediator, queues.show_rewarded, callback)
else
mediator_error(VIDEO, callback)
end
return nil
end

---Loads interstitial ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function M.load_interstitial(callback)
if M.is_video_setup() then
mediator.call_next(video_mediator, queues.load_interstitial, callback)
return mediator.call_next(video_mediator, queues.load_interstitial, callback)
else
mediator_error(VIDEO, callback)
end
return nil
end

---Shows interstitial ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function M.show_interstitial(callback)
if M.is_video_setup() then
mediator.call(video_mediator, queues.show_interstitial, callback)
return mediator.call(video_mediator, queues.show_interstitial, callback)
else
mediator_error(VIDEO, callback)
end
return nil
end

---Loads banner for for next network.
---@param callback function the function is called after execution.
---@return integer|nil
function M.load_banner(callback)
if M.is_banner_setup() then
mediator.call_next(banner_mediator, queues.load_banner, callback)
return mediator.call_next(banner_mediator, queues.load_banner, callback)
else
mediator_error(BANNER, callback)
end
return nil
end

---Shows setup banner for next network. Hides the previous banner if it was displayed.
---@param callback function the function is called after execution.
---@return integer|nil
function M.show_banner(callback)
if M.is_banner_setup() then
banner_hided = false
mediator.call(banner_mediator, queues.show_banner, function(response)
return mediator.call(banner_mediator, queues.show_banner, function(response)
if banner_auto_hide and banner_hided then
M.hide_banner()
end
Expand All @@ -291,6 +302,7 @@ function M.show_banner(callback)
else
mediator_error(BANNER, callback)
end
return nil
end

---Hides setup banner for current network
Expand Down Expand Up @@ -394,4 +406,10 @@ function M.get_next_network(check_banner)
return network
end

---Cancel execution
---@param id integer
function M.cancel(id)
mediator.cancel(id)
end

return M
11 changes: 11 additions & 0 deletions ads_wrapper/autocomplite/ads_wrapper/ads_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,37 @@ end

---Loads rewarded ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.load_rewarded(callback)
end

---Shows rewarded ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.show_rewarded(callback)
end

---Loads interstitial ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.load_interstitial(callback)
end

---Shows interstitial ads for next network
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.show_interstitial(callback)
end

---Loads banner for all setup networks.
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.load_banner(callback)
end

---Shows setup banner for next network. Hides the previous banner if it was displayed.
---@param callback function the function is called after execution.
---@return integer|nil
function ads_wrapper.show_banner(callback)
end

Expand Down Expand Up @@ -141,4 +147,9 @@ end
function ads_wrapper.get_next_network(check_banner)
end

---Cancel execution
---@param id integer
function ads_wrapper.cancel(id)
end

return ads_wrapper
7 changes: 7 additions & 0 deletions ads_wrapper/autocomplite/ads_wrapper/mediator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ end
---@param mediator mediator
---@param q queue queue object
---@param callback function callback accepting the response result
---@return integer
function mediator.call(mediator, q, callback)
end

---Tries to complete queue for current network in mediator
---@param mediator mediator
---@param q queue queue object
---@param callback function callback accepting the response result
---@return integer
function mediator.call_current(mediator, q, callback)
end

Expand All @@ -54,4 +56,9 @@ end
function mediator.add_networks(to, from)
end

---Cancel execution
---@param id integer
function mediator.cancel(id)
end

return mediator
6 changes: 6 additions & 0 deletions ads_wrapper/autocomplite/ads_wrapper/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ end
---@param queue table
---@param network network
---@param callback function callback accepting the response result
---@return integer
function queue.run(queue, network, callback)
end

Expand All @@ -24,4 +25,9 @@ end
function queue.add(queue, fn)
end

---Cancel queue execution
---@param id integer
function queue.cancel(id)
end

return queue
Loading

0 comments on commit c5578b9

Please sign in to comment.