attachInterrupt function doesn't work within a while loop?

I am finding that the bonescript attachInterrupt function doesn’t seem to work when the program is in a while statement. I need to loop indefinitely while monitoring a process. As part of the monitoring I need to record a switch closing so that’s where the interrupt comes in…

The interrupt here works just fine, but it doesn’t loop so I can do the rest of the monitoring and logging functions I want to do:

var b = require(‘bonescript’);
var cycles=0;
var inputPin = ‘P8_19’;
b.pinMode(inputPin, b.INPUT);
b.attachInterrupt(inputPin, true, b.CHANGE, cyclecounter);

function cyclecounter() {
cycles++);
}

In this code the while loop allows me to monitor and log, but the interrupt doesn’t work from within the while loop, so I can’t record cycles:

var b = require(‘bonescript’);
var cycles=0;
var inputPin = ‘P8_19’;
b.pinMode(inputPin, b.INPUT);
b.attachInterrupt(inputPin, true, b.CHANGE, cyclecounter);
while (true){
//extensive code to monitor and log a process external to the beaglebone black
}

function cyclecounter() {
cycles++);
}

Is there a way I can setup an interrupt function within a while loop?

This is my first time working with interrupts so I may be missing something obvious… but if anyone can point me in the right direction it would be greatly appreciated.

Cheers