Comparison

util/async.lua @ 8408:b751bee6a829

util.async: Fix thread check to work correctly in Lua 5.2 coroutine.running() now returns the main thread and a boolean true if called from the main thread, as opposed to nil in 5.1
author Kim Alvefur <zash@zash.se>
date Tue, 21 Nov 2017 21:48:43 +0100
parent 8407:f652e1ea2f69
child 8600:96f20cf92b84
comparison
equal deleted inserted replaced
8407:f652e1ea2f69 8408:b751bee6a829
1 local log = require "util.logger".init("util.async"); 1 local log = require "util.logger".init("util.async");
2 2
3 local function checkthread() 3 local function checkthread()
4 local thread = coroutine.running(); 4 local thread, main = coroutine.running();
5 if not thread then 5 if not thread or main then
6 error("Not running in an async context, see https://prosody.im/doc/developers/util/async"); 6 error("Not running in an async context, see https://prosody.im/doc/developers/util/async");
7 end 7 end
8 return thread; 8 return thread;
9 end 9 end
10 10