Skip to content

Commit

Permalink
Merge pull request #5 from moonlibs/4-syncpool-failed-at-terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
Mons authored Apr 27, 2023
2 parents 75962c7 + 2a01da8 commit 65553d0
Show file tree
Hide file tree
Showing 10 changed files with 392 additions and 69 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
- uses: tarantool/setup-tarantool@v2
with:
tarantool-version: '2.10.4'
- name: install luacov-console
run: tarantoolctl rocks install luacov-console
- name: install luacov-coveralls
run: tarantoolctl rocks install --server=http://luarocks.org luacov-coveralls
- name: setup perl
uses: shogo82148/actions-setup-perl@v1
with:
Expand All @@ -24,5 +28,13 @@ jobs:
cpanm -v
cpanm --notest TAP::Harness
- name: run tests
env:
LUACOV_ENABLE: true
run: |
make test
make test
- name: print luacov-console report
run: .rocks/bin/luacov-console "$(pwd)" && .rocks/bin/luacov-console -s
- name: publish coveralls report
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: .rocks/bin/luacov-coveralls -v
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
std="tarantool"

max_line_length=140
include_files = {"sync/", "sync.lua"}
16 changes: 16 additions & 0 deletions .luacov
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
exclude = {
"test/",
"%.rocks/",
"builtin/",
}

runreport = false
deletestats = false

coveralls = {
root = "/",
debug = true,
pathcorrect = {
{ "^/home/runner/work/sync/sync/", "" },
},
}
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Coverage Status](https://coveralls.io/repos/github/moonlibs/sync/badge.svg?branch=master)](https://coveralls.io/github/moonlibs/sync?branch=master)

# Collection of synchronization primitives for Tarantool fibers

## Conditional Variable (cond)
Expand Down Expand Up @@ -111,6 +113,33 @@ pool:wait() -- pool can be awaited
print("pool finished")
```

sync.pool is usefull in background fibers when you need to parallel networks requests
```lua

function job:start()
self.fiber_f = fiber.create(function()
local pool = sync.pool('fetches', 4)
while self.is_active do
for _, user in box.space.users:pairs() do
if self.is_active then
-- fast exit
break
end
pool:send(process_user_network, {user})
end
end
pool:terminate()
if not pool:wait(gracefull_timeout) then
-- terminate pool with force
log.warn("forcefully terminating pool")
pool:terminate(true)
pool:wait()
end
end)
end

```

## More plans and ideas to implement

There are several ideas may be implemented. PR's or proposals are welcome
Expand Down
2 changes: 1 addition & 1 deletion sync.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local sync = {
_VERSION = '0.10.0',
_VERSION = '0.10.1',
}

sync.cond = require 'sync.cond'
Expand Down
7 changes: 7 additions & 0 deletions sync/cond.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
local fiber = require "fiber"

---@class sync.cond
---@field name string
---@field timeout number? default timeout for :recv()
local cond = {}
cond.__index = cond
cond.__tostring = function (self) return "cond<".. (self.name or 'anon') ..">" end
setmetatable(cond, { __call = function (_, ...) return _.new(...) end })

---Creates new sync.cond
---@param name string? name of sync.cond
---@param timeout number? default timeout for sync.recv
---@return sync.cond
function cond.new(name, timeout)
if name == cond then error("Usage: cond.new([name]) or cond([name]) (not cond:new())", 2) end
return setmetatable({
Expand Down
Loading

0 comments on commit 65553d0

Please sign in to comment.