How to cancel a task timeout from task manager?

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

einbroch
Human
Human
Posts: 21
Joined: 14 May 2011, 10:22
Noob?: Yes

How to cancel a task timeout from task manager?

#1 Post by einbroch »

Hi I have two subroutine hooks the other one is depending on the other hook. I want to set a timeout for the other subroutine and when the other subroutine is called I want to end the timeout task for the previous subroutine. Here is what I did but doesn't work:

# deal stages

Code: Select all

my $dealAddZeny = @_;
my $dealFinalize = @_;

Code: Select all

sub onDealRequest{
	my ($self, $args) = @_;

			#kill time out how?
			$taskManager->add(new Task::Timeout(
				function => sub { 
					my ($dealAddZeny) = @_;
					Commands::run("deal no");
					message("waited too long to add zeny\n","system");			
				},
				seconds => $itemWaitTime,
			));
}

Code: Select all

sub onDealAddOther{
	my ($self, $args) = @_;
			#kill time out how?
			$dealAddZeny->setDone();
			$taskManager->add(new Task::Timeout(
				function => sub { 
					my ($dealFinalize) = @_;
					Commands::run("deal no");
					message("waited too long to finalize deal\n","system");
				},
				seconds => $itemWaitTime,
			));
}
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: How to cancel a task timeout from task manager?

#2 Post by EternalHarvest »

Use 'stop => 1' when creating Task::Timeout (that needed only for that task, explained in its documentation) and store task object before adding it to task manager ($taskManager->add($task = new Task...)). Then, when you need to cancel it, call $task->stop.
einbroch
Human
Human
Posts: 21
Joined: 14 May 2011, 10:22
Noob?: Yes

Re: How to cancel a task timeout from task manager?

#3 Post by einbroch »

Thanks!. I will post the code for other's reference.

Code: Select all

$taskManager->add($dealAddZeny = new Task::Timeout(
	function => sub { 
		Commands::run("deal no");
		message("waited too long to add zeny\n","system");			
	},
	seconds => $zenyWaitTime,
	stop => 1,
));

$dealAddZeny->stop();