Skip to content

Commit 890de9e

Browse files
committed
fully remove forEach async
1 parent 91ba8b1 commit 890de9e

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

packages/core/src/awsService/ec2/activation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { Ec2ConnecterMap } from './connectionManagerMap'
2222
import { ec2LogsScheme } from '../../shared/constants'
2323
import { Ec2LogDocumentProvider } from './ec2LogDocumentProvider'
24+
import { mapOverMap } from '../../shared/utilities/collectionUtils'
2425

2526
const connectionManagers = new Ec2ConnecterMap()
2627

@@ -83,5 +84,5 @@ export async function activate(ctx: ExtContext): Promise<void> {
8384
}
8485

8586
export async function deactivate(): Promise<void> {
86-
connectionManagers.forEach(async (manager) => await manager.dispose())
87+
await mapOverMap(connectionManagers, async (_, manager) => await manager.dispose())
8788
}

packages/core/src/awsService/ec2/remoteSessionManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { EC2, SSM } from 'aws-sdk'
77
import { SsmClient } from '../../shared/clients/ssmClient'
88
import { Disposable } from 'vscode'
9+
import { mapOverMap } from '../../shared/utilities/collectionUtils'
910

1011
export class Ec2SessionTracker extends Map<EC2.InstanceId, SSM.SessionId> implements Disposable {
1112
public constructor(
@@ -31,7 +32,7 @@ export class Ec2SessionTracker extends Map<EC2.InstanceId, SSM.SessionId> implem
3132
}
3233

3334
public async dispose(): Promise<void> {
34-
this.forEach(async (_sessionId, instanceId) => await this.disconnectEnv(instanceId))
35+
await mapOverMap(this, async (_, instanceId) => await this.disconnectEnv(instanceId))
3536
}
3637

3738
public isConnectedTo(instanceId: EC2.InstanceId): boolean {

packages/core/src/codewhisperer/service/importAdderProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class ImportAdderProvider implements vscode.CodeLensProvider {
5555
) {
5656
const line = findLineToInsertImportStatement(editor, firstLineOfRecommendation)
5757
let mergedStatements = ``
58-
r.mostRelevantMissingImports?.forEach(async (i) => {
58+
r.mostRelevantMissingImports?.forEach((i) => {
5959
// trust service response that this to-be-added import is necessary
6060
if (i.statement) {
6161
mergedStatements += i.statement + '\n'

packages/core/src/shared/utilities/collectionUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,7 @@ export function createCollectionFromPages<T>(...pages: T[]): AsyncCollection<T>
566566
export function isPresent<T>(value: T | undefined): value is T {
567567
return value !== undefined
568568
}
569+
570+
export async function mapOverMap<K, V, O>(m: Map<K, V>, f: (k: K, v: V) => Promise<O>): Promise<O[]> {
571+
return await Promise.all(Array.from(m).map(async ([k, v]) => await f(k, v)))
572+
}

packages/core/src/test/lambda/commands/listSamResources.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('listSamResources', () => {
6262
{ name: 'stringify array', value: '[]' },
6363
{ name: 'array object', value: [] },
6464
]
65-
testcases.forEach(async ({ name, value }) => {
65+
testcases.forEach(({ name, value }) => {
6666
it(`returns empty array given SAM CLI return ${name} given any issue`, async () => {
6767
runSamCliListResourceStub.resolves(value)
6868

packages/core/src/test/shared/fs/fs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ describe('FileSystem', function () {
218218
describe('mkdir()', function () {
219219
const paths = ['a', 'a/b', 'a/b/c', 'a/b/c/d/']
220220

221-
paths.forEach(async function (p) {
221+
paths.forEach(function (p) {
222222
it(`creates folder: '${p}'`, async function () {
223223
const dirPath = testFolder.pathFrom(p)
224224
await fs.mkdir(dirPath)
225225
assert(existsSync(dirPath))
226226
})
227227
})
228228

229-
paths.forEach(async function (p) {
229+
paths.forEach(function (p) {
230230
it(`creates folder but uses the "fs" module if in Cloud9: '${p}'`, async function () {
231231
sandbox.stub(extensionUtilities, 'isCloud9').returns(true)
232232
const dirPath = testFolder.pathFrom(p)

0 commit comments

Comments
 (0)