Merge: lib/popcorn: introduce tasks
authorJean Privat <jean@pryen.org>
Wed, 17 May 2017 13:53:38 +0000 (09:53 -0400)
committerJean Privat <jean@pryen.org>
Wed, 17 May 2017 13:53:38 +0000 (09:53 -0400)
This PR is based on #2436

## Popcorn threaded tasks

 Tasks allow you to execute code in another thread than the app listening loop.
 Useful when you want to run some tasks periodically.

 Let's say you want to purge the `downloads/` directory of your app every hour:

~~~nit
 class PurgeTask
super PopTask

var dir: String

redef fun main do
loop
dir.rmdir
3600.sleep
end
end
 end

 var app = new App

 # Register a new task
 app.register_task(new PurgeTask("downloads/"))

 # Add your handlers
 # app.use('/', new MyHandler)

 # Run the tasks
 app.run_tasks

 # Start the app
 app.listen("0.0.0.0", 3000)
~~~

Pull-Request: #2437
Reviewed-by: Jean Privat <jean@pryen.org>


Trivial merge