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)
commit6d3a81a7ac5b7d468b3fd740b3ff90a68aa137b8
treef57f7c3b0b68c2d6f018c3a0fe65b999261275d8
parente9166ed72bf2a25802039b194b0d54b1336efd28
parentf56782cd67b47bd9ed99944691e96a25a9ee875b
Merge: lib/popcorn: introduce tasks

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>