Without getting into something like Webworkers
, the only thing you can do is have your operation
function track how long it's been running and bail out if it has gone on too long.
Of course, this could leave things in an inconsistent state.
If you are trying to process something and it is taking too long, you can use setTimeout
to do things in small chunks at a time.
If you are really lucky to be able to target just the latest-and-greatest browsers and ignore IE, Generator Functions
can be magic -- but few of us are that lucky.