Skip to content

Implement pool for managing forks #718

@novemberborn

Description

@novemberborn

For #78 we'll end up limiting the number of concurrent forks. We should implement a pool of forks that the Api can use to run each test file.

Here's a rough sketch of a possible implementation:

import assert from 'assert'
import fork from './fork'

class Pool extends EventEmitter {
  constructor (limit) {
    this.limit = limit
    this.active = 0
  }

  fork (file, opts) {
    assert(this.active < this.limit)

    this.active++
    const promise = fork(file, opts)
    promise.catch(() => {}).then(() => {
      this.active--
      this.emit('free')
    })
    return promise
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions