Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Make package.activate() async. #4059

Closed
Closed

Description

@bolinfest

I think that PackageManager and Package should be resigned to be truly async and make heavy use of ES6 Promises (removing the dependency on Q). For example, package.activate() should have the option to return a Promise, and the package should not be considered "loaded" until that Promise is resolved.

Then it would be possible to depend on other packages as follows:

  activate: (state) ->
    # This package is not considered activated until the shared-logging package is activated.
    return atom.packages.activate 'shared-logging'

Then PackageManager and Package would have to be updated to use these Promises all the way through. For example, Package.activateNow() would have to become something like:

  activateNow: ->
    try
      @activateConfig()
      @activateStylesheets()
      if @requireMainModule()
        maybePromise = @mainModule.activate(atom.packages.getPackageState(@name) ? {})
        if maybePromise instanceof Promise: # or maybe just check for then() method
          return maybePromise
        else
          return Promise.resolve null
    catch e
      console.warn "Failed to activate package named '#{@name}'", e.stack

and callers of activateNow() would invoke then() on the return value, as appropriate.

Activity

  1. mark-hahn commented on Nov 4, 2014

    @mark-hahn
    Contributor

    I've solved package async problems in the past using process.nextTick.
    This isn't good enough? Promises may be cleaner but refactoring that much
    is a pain.

    On Tue, Nov 4, 2014 at 11:08 AM, bolinfest [email protected] wrote:

    I think that PackageManager and Package should be resigned to be truly
    async and make heavy use of ES6 Promises (removing the dependency on Q).
    For example, package.activate() should have the option to return a Promise,
    and the package should not be considered "loaded" until that Promise is
    resolved.

    Then it would be possible to depend on other packages as follows:

    activate: (state) ->
    # This package is not considered activated until the shared-logging package is activated.
    return atom.packages.activate 'shared-logging'

    Then PackageManager and Package would have to be updated to use these
    Promises all the way through. For example, Package.activateNow() would
    have to become something like:

    activateNow: ->
    try
    @activateConfig()
    @activateStylesheets()
    if @requireMainModule()
    maybePromise = @mainModule.activate(atom.packages.getPackageState(@name) ? {})
    if maybePromise instanceof Promise: # or maybe just check for then() method
    return maybePromise
    else
    return Promise.resolve null
    catch e
    console.warn "Failed to activate package named '#{@name}'", e.stack

    and callers of activateNow() would invoke then() on the return value, as
    appropriate.

    —
    Reply to this email directly or view it on GitHub
    #4059.

  2. bolinfest commented on Nov 4, 2014

    @bolinfest
    ContributorAuthor

    If activate(state) could return an arbitrary Promise, there's no guarantee that it would be resolved on the next tick (nor should it have to). For example, activate() might read from a configuration file asynchronously and do some set up based on that before it should consider itself activated.

  3. karloluis commented on Nov 5, 2014

    @karloluis

    Seems that it might improve a bit if re-done. But it does sound like a headache. IMO Better now than later, it might become even more convoluted and it might shave off some more loading time.

  4. lock commented on Apr 1, 2018

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  5. locked and limited conversation to collaborators on Apr 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions