You can't use a promise here. Promises are fulfilled only once, so this will never get called after the first key press. I assume all you're trying to do here is only call `postMessage` after the library has been indexed, so just write a wrapper function that checks a flag if indexing has completed or not, calling this function immediately if it has and waiting until indexing has completed if not (which you *can* use a promise for).