-
-
Notifications
You must be signed in to change notification settings - Fork 197
Detach event handlers after action is done #2703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+11 −0 | helpers.ts | |
+12 −16 | logger.ts | |
+119 −0 | test/unit-tests/logger.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import * as helpers from "../common/helpers"; | |
import * as semver from "semver"; | ||
import { EventEmitter } from "events"; | ||
import { AppFilesUpdater } from "./app-files-updater"; | ||
import { attachAwaitDetach } from "../common/helpers"; | ||
import * as temp from "temp"; | ||
temp.track(); | ||
let clui = require("clui"); | ||
|
@@ -425,10 +426,13 @@ export class PlatformService extends EventEmitter implements IPlatformService { | |
await this.trackActionForPlatform({ action: "Build", platform, isForDevice }); | ||
|
||
let platformData = this.$platformsData.getPlatformData(platform, projectData); | ||
platformData.platformProjectService.on(constants.BUILD_OUTPUT_EVENT_NAME, (data: any) => { | ||
const handler = (data: any) => { | ||
this.emit(constants.BUILD_OUTPUT_EVENT_NAME, data); | ||
}); | ||
await platformData.platformProjectService.buildProject(platformData.projectRoot, projectData, buildConfig); | ||
this.$logger.printInfoMessageOnSameLine(data.data.toString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we have this line and we do no have it in the other cases when we use attachAwaitDetach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need in order to keep the current behavior when using
Bottom line - you need this in the unlikely case that you spawn with |
||
}; | ||
|
||
await attachAwaitDetach(constants.BUILD_OUTPUT_EVENT_NAME, platformData.platformProjectService, handler, platformData.platformProjectService.buildProject(platformData.projectRoot, projectData, buildConfig)); | ||
|
||
let prepareInfo = this.$projectChangesService.getPrepareInfo(platform, projectData); | ||
let buildInfoFilePath = this.getBuildOutputPath(platform, platformData, buildConfig); | ||
let buildInfoFile = path.join(buildInfoFilePath, buildInfoFileName); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case this method fails before returning the Promise (for example in case the implementation is:
current code will fail during evaluation of method arguments and will never emit error event for the operation. Is this expected?
Note: I know we are using
async
keyword in such cases that will always generate Promise for us and we should never end up in a case where we fail before creating the Promise, but anyway, I want to be sure that's the behaviour we want.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should be the caller's responsibility to keep track of the arguments. If one of the arguments need to be prepared in some way (e.g. to be
try...catch
-ed) it should be done prior to calling the method.As for the example you've provided I see no problem with it - failing during evaluation of the arguments will lead to the event handler not being attached in the first place and this method's main target is preventing leakage of event handlers.