chrome-promise | Promises for chrome JavaScript APIs | Reactive Programming library

 by   tfoxy TypeScript Version: 3.0.5 License: MIT

kandi X-RAY | chrome-promise Summary

kandi X-RAY | chrome-promise Summary

chrome-promise is a TypeScript library typically used in Programming Style, Reactive Programming applications. chrome-promise has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.

Promises for chrome JavaScript APIs used in extensions and apps.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              chrome-promise has a low active ecosystem.
              It has 149 star(s) with 12 fork(s). There are 7 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 3 open issues and 21 have been closed. On average issues are closed in 106 days. There are 6 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of chrome-promise is 3.0.5

            kandi-Quality Quality

              chrome-promise has 0 bugs and 0 code smells.

            kandi-Security Security

              chrome-promise has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              chrome-promise code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              chrome-promise is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              chrome-promise releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of chrome-promise
            Get all kandi verified functions for this library.

            chrome-promise Key Features

            No Key Features are available at this moment for chrome-promise.

            chrome-promise Examples and Code Snippets

            No Code Snippets are available at this moment for chrome-promise.

            Community Discussions

            QUESTION

            In a Chrome extension, how to ensure previous promise resolves before the next one using chrome-promise?
            Asked 2018-Jun-02 at 23:42

            I've been using the chrome-promise library to wrap the Chrome extension API with a facade that returns promises instead of using callbacks. This has generally worked quite well, but I seem to be running into an issue with chrome.storage.local APIs.

            My extension's event page listens for the chrome.tabs.onActivated and chrome.tabs.onRemoved events. When it gets the onActivated event, it adds the tab info to an array and calls chrome.storage.local.set(data) to store the updated array in local storage.

            When it gets the onRemoved event, it calls chromepromise.storage.local.get(null).then(...) to get the list of tabs via a promise, removes the tab info from the array, and then calls chrome.storage.local.set() again to save the updated array.

            The issue is that the onActivated event seems to trigger before the promise flow from the onRemoved event resolves. So the onActivated handler retrieves the old stored array, with the closed tab still in it, and then pushes the newly activated tab. So the stored tab data now includes a tab that's already been closed.

            I'm assuming this is an issue with using promises instead of callbacks, but I'm wondering if anyone else has run into this problem with this library and worked around it.

            Update

            As wOxxOm points out, this is a generic problem with "arbitrating unpredictable asynchronous access to a single resource such as chrome.storage" and not unique to the chrome-promise library.

            After researching a bit, I came up with a couple solutions, added as answers below. One uses a mutex to ensure (I think) that one promise chain's getting and setting data in chrome.storage completes before the next one starts. The other queues the whole promise chain that's created from an event and doesn't start the next one until the current one has fully completed. I'm not sure which is better, though I suppose locking for a shorter period of time is better.

            Any suggestions or better answers are welcome.

            ...

            ANSWER

            Answered 2018-Jun-02 at 23:42
            Mutex

            Update: I ended up using the approach below to create a module that uses a mutex to ensure gets and sets of the Chrome extension storage maintain their order. It seems to be working well so far.

            This solution uses the mutex implementation from this article. addTab() and removeTab() call storageMutex.synchronize() with a function that does all the storage getting and setting. This should prevent later events from affecting the storage of earlier events.

            The code below is a very simplified version of the extension, but it does run. The playNextEvent() calls at the bottom simulate opening 4 tabs, switching back to tab 2 and closing it, which then causes tab 3 to activate. setTimeout()s are used so that everything doesn't run as one long call stack.

            Source https://stackoverflow.com/questions/47193925

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install chrome-promise

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • npm

            npm i chrome-promise

          • CLONE
          • HTTPS

            https://github.com/tfoxy/chrome-promise.git

          • CLI

            gh repo clone tfoxy/chrome-promise

          • sshUrl

            git@github.com:tfoxy/chrome-promise.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link