Ruby code in filter does not executed in sequence

I have an input CSV file that I want to parse with logstash. I want to maintain a variable across events loaded from the file, using a variable in the Ruby code.

I have an issue so I write a simple CSV input file and a simple logstash.conf file as follow:

The csv file contains only 1 column with a sequence of number:
1
2
3
...
999

logstash.conf:

filter 
{  
    csv 
	{
        	columns => ["line"]
	}
	ruby
	{
		init => 
		"			
			@i = 0
		" 
		code => 
		"
			@i = @i + 1
			event['i'] = @i
		"
	}
}
output 
{  
	stdout 
	{
       	codec => rubydebug
    }
}

When I execute logstash, I see that few events are not in the good order;for example:

"message" => "62",
"line" => "62",
"i" => 91

I do not understand the reason, so I could not use a variable in the Ruby code to maintain a context between 2 successive events (with a same property).

Do you have any idea ?