Tom6 Posted April 12, 2020 Share Posted April 12, 2020 Hi, I'm using the script filter component to get results from a custom node.js application My code takes ~2 seconds to run, but I can provide 50% of the value in less than 100ms. My question is - if it's possible to return 2 times from my app. 1) 'preliminary results'. after which my code is still running, and then when it's ready: 2) 'full results' (which will override the results from before. well, actually, the prelimnary results are a subset of the full results Is it possible? If not, how would you 'solve' this problem? (waiting 2 seconds every time is too much) Thanks Link to comment
deanishe Posted April 12, 2020 Share Posted April 12, 2020 (edited) You can't literally return twice, but you can tell Alfred to re-run your Script Filter by setting rerun at the top level of the JSON feedback. There are a couple of general ways you could handle such a situation. If the results aren't time sensitive, you could simply always fetch the full set but cache them. Then you always load and show the results directly from cache, but if they're out of date, start a background process to refresh the cache, and then reload the cache when it's done. That way, the first time the user runs the workflow, it'll take 2 seconds to run, but after that it will be instant, although it will still take 2 seconds for the results to be updated to current. If showing old data isn't acceptable, you could cache the preliminary results (if they aren't also included in the full set) and return them, and set rerun and a workflow variable via the JSON feedback (top-level variables are passed back to your script on rerun) to tell your scripts it's the second run and it should now go and fetch the full result set. Then when it finishes, it can merge the cached preliminary results back in before returning the full results. If you're writing your workflow in Python or Go, my libraries (linked in my signature) have a bunch of functions to help with exactly this kind of thing. Edited April 12, 2020 by deanishe Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now