我有一个代码如下:执行星号回调的Perl命令?
1 sub do_leave {
2
3 my ($asterisk, $event) = @_;
4 my $join_id;
5 my $id = $astman->send_action({ Action => 'Getvar',
6 Variable => 'join_id',
7 Channel => $event->{'Channel'},
8 }, \&get_value, undef, \$join_id);
9
10 sleep(2);
11 say "join_id is: $join_id";
12
13 my $sql = "UPDATE conference_log SET duration=(TIMESTAMPDIFF(SECOND, (SELECT start_conf), NOW())), end_conf=(NOW()) WHERE id=?";
14 my $sth = $dbh->prepare($sql);
15 $sth->execute($join_id);
16 }
17
18 sub get_value {
19 my ($ast, $resp, $ref_join_id) = @_;
20 for my $key (keys %$resp) {
21 if ($key eq "PARSED") {
22 $$ref_join_id = $resp->{$key}{"Value"};
23 }
24 }
25 }
我使用Asterisk::AMI模块,用于从星号AMI获取信息。 do_leave
子每当有人离开会议时被调用。我的问题是get_value
在do_leave
的所有语句后执行的回调。 如何在第10行之前执行get_value
回调。变量\$join_id
在send_action
是回调的第三个参数。在sql语句之前,我需要$join_id
变量。
是'send_id'保证调用'get_value'回调?所以你只是想在更新数据库之前确保回调已经被执行了?在这种情况下,我会立刻为您准备好*期货*的解决方案。 – amon
@amon yes send_action将会执行'get_value'回调,但是在数据库更新之后,它在执行之前也不会做任何事情,因为'$ sth-> execute($ join_id);'needs'join_id'。 –