summaryrefslogtreecommitdiff
path: root/server-beta/src/service/service.lua
blob: 3712b7b8c66d5f61c6c03b04c235a82ea0986c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local pub        = require 'pub'
local thread     = require 'bee.thread'
local task       = require 'task'
local timer      = require 'timer'
local proto      = require 'proto'

local m = {}
m.type = 'service'

function m.listenPub()
    task.create(function ()
        while true do
            pub.checkDead()
            pub.recieve()
            task.sleep(0)
        end
    end)
end

function m.startTimer()
    local last = os.clock()
    while true do
        thread.sleep(0.001)
        local current = os.clock()
        local delta = current - last
        last = current
        timer.update(delta)
    end
end

function m.start()
    pub.recruitBraves(4)
    task.setErrorHandle(log.error)
    proto.listen()
    m.listenPub()

    m.startTimer()
end

return m