[Vala] [Valum]help with process async method.
- From: Matrix <pigex zhang gmail com>
- To: "vala-list gnome org" <vala-list gnome org>
- Subject: [Vala] [Valum]help with process async method.
- Date: Tue, 24 Nov 2015 20:59:42 +0800
Hi:
i'm writing a server side program with valum framework...
in one entry point, the server will send a http request to a remote
server,
i copy the https://wiki.gnome.org/Projects/Vala/AsyncSamples in my code
to test
async double do_calc_in_bg(double val) throws ThreadError {
SourceFunc callback = do_calc_in_bg.callback;
double[] output = new double[1];
// Hold reference to closure to keep it from being freed whilst
// thread is active.
ThreadFunc<void*> run = () => {
// Perform a dummy slow calculation.
// (Insert real-life time-consuming algorithm here.)
double result = 0;
for (int a = 0; a<10000000; a++)
result += val * a;
// Pass back result and schedule callback
output[0] = result;
Idle.add((owned) callback);
return null;
};
Thread.create<void*>(run, false);
// Wait for background thread to schedule our callback
yield;
return output[0];
}
void test(Request request, Response response) {
do_calc_in_bg.begin(0.001, (obj, res) => {
try {
double result = do_calc_in_bg.end(res);
response.write_all(@"yes, the result is $result".data, null);
} catch (ThreadError e) {
string msg = e.message;
stderr.printf(@"Thread error: $msg\n");
}
});
}
but when the thread finished, call the response.write_all, it fails ...
2015-11-24 20:37:32: (mod_fastcgi.c.2391) unexpected end-of-file
(perhaps the fastcgi process died): pid: 6667 socket:
unix:/opt/projects/platformX/install/valum.sock-0
2015-11-24 20:37:32: (mod_fastcgi.c.3172) response not received,
request sent: 548 on socket:
unix:/opt/projects/platformX/install/valum.sock-0 for
/verify_code?phone=13300000000, closing connection
how to implement async method ?
3ks a lot!!!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]