Skip to content

Instantly share code, notes, and snippets.

@exodist
Created May 3, 2017 17:21
Show Gist options
  • Save exodist/aa116f6884338adcc547618a4f440fd8 to your computer and use it in GitHub Desktop.
Save exodist/aa116f6884338adcc547618a4f440fd8 to your computer and use it in GitHub Desktop.
test.pl
use strict;
use warnings;
use Test::More;
use Test2::API qw/context/;
my @tasks;
sub enqueue(&) {
my $ctx = context(); # Gets the context created by 'is_later'
# Snapshot is safe to pass around, unlike the actual context.
push @tasks, [shift, $ctx->snapshot];
$ctx->release;
}
sub is_later {
my ($arg) = @_;
my $ctx = context; # To put the context in place
enqueue {
is $arg, 0, "test $arg";
};
$ctx->release;
}
sub event_loop {
while (@tasks) {
my ($task, $ctx) = @{shift @tasks};
$ctx->do_in_context($task);
}
}
is_later 1; # all the failures from these are reported for line 14,
is_later 2; # but i'd like them reported for line 24-27
is_later 0;
is_later 3;
event_loop;
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment