Create latches before calling Javascript. Fixes #2.
Merge pull request #2 from akaihola/issue-2-timeout

JavaScript calls occasionally fail