thomasp85/fiery

a newcomer's question about Cycle, Message and Block

Closed this issue · 1 comments

I just read the fiery reference manual from CRAN. I have several questions (maybe silly).

Cycle

The "minimal example" shutdown automatically after several seconds. It seems the following code does it.

# Count the number of cycles (internal loops)
app$on('cycle-start', function(server, ...) {
    server$set_data('cycles', server$get_data('cycles') + 1)
})

# Terminate the server after 50 cycles
app$on('cycle-end', function(server, ...) {
    if (server$get_data('cycles') > 50) {
        message('Ending...')
        flush.console()
        server$extinguish()
    }
})

What is the block "Count the number of cycles (internal loops)" does? i.e., what does internal loops mean? How the cycles becomes greater than 50? What's cycle in cycle-start and cycle-end?

Message

In the Life Cycle Events, there are before-message, message, after-message. I don't know what is websocket message. Is there any explanation about it? Or I should read some document/book (any suggestion?)

Block

What does the block argument in app$ignite(block = TRUE) do? How this argument affect the server? i.e., Does it mean a new process/session start when two or more users request the same resource in the same time?

  1. fiery handles requests in blocks, collecting them in a queue and then processing them (usually the queue will never get longer than one). The processing of a queue is a cycle

  2. there is plenty of literature on websockets and how they work scattered across the internet. I’m not going to list specifics as I don’t know what is best right now

  3. setting block = FALSE launches the server in a way where you can still interact with the terminal (it doesn’t block it)