Skip to content

Commit

Permalink
Use p-queue instead of PromiseQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 1, 2024
1 parent 15ab419 commit 30082ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
"eventemitter3": "^5.0.1",
"lodash": "^4.17.21",
"p-timeout": "^6.1.2",
"promise-queue": "^2.2.5",
"sleep-promise": "^9.1.0",
"typescript-memoize": "^1.1.1"
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
"@types/lodash": "^4.14.202",
"@types/promise-queue": "^2.2.3",
"@types/w3c-image-capture": "^1.0.10",
"@types/w3c-web-usb": "^1.0.10",
"@types/wicg-file-system-access": "^2023.10.4",
Expand All @@ -66,6 +64,7 @@
"file-saver": "^2.0.5",
"linearly": "^0.21.0",
"npm-run-all": "^4.1.5",
"p-queue": "^8.0.1",
"prettier": "^3.2.4",
"stylus": "^0.62.0",
"typescript": "^5.3.3",
Expand Down
12 changes: 6 additions & 6 deletions src/PTPDevice.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventEmitter from 'eventemitter3'
import PQueue from 'p-queue'
import promiseTimeout from 'p-timeout'
import PromiseQueue from 'promise-queue'
import sleep from 'sleep-promise'

import {ResCode} from './PTPDatacode'
Expand Down Expand Up @@ -75,7 +75,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {

#opened = false

#commandQueue = new PromiseQueue(1, Infinity)
#queue = new PQueue({concurrency: 1})

#console = console as Pick<Console, 'groupCollapsed' | 'groupEnd' | 'info'>

Expand Down Expand Up @@ -149,7 +149,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
groupCollapsed: () => null,
groupEnd: () => null,
info: () => null,
}
}
}

onEventCode(eventCode: number, callback: PTPEventCallback) {
Expand All @@ -173,7 +173,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
{milliseconds: PTPDefaultTimeoutMs, message: 'Timeout'}
).finally(this.#console.groupEnd)

return this.#commandQueue.add(queue)
return this.#queue.add(queue) as Promise<PTPResponse>
}

sendData = (option: PTPSendDataOption): Promise<PTPResponse> => {
Expand All @@ -187,7 +187,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
{milliseconds: PTPDefaultTimeoutMs, message: 'Timeout'}
).finally(this.#console.groupEnd)

return this.#commandQueue.add(queue)
return this.#queue.add(queue) as Promise<PTPResponse>
}

receiveData = (option: PTPReceiveDataOption): Promise<PTPDataResponse> => {
Expand All @@ -201,7 +201,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
{milliseconds: PTPDefaultTimeoutMs, message: 'Timeout'}
).finally(this.#console.groupEnd)

return this.#commandQueue.add(queue)
return this.#queue.add(queue) as Promise<PTPDataResponse>
}

private sendCommandNow = async (
Expand Down
18 changes: 8 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,6 @@
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8"
integrity sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==

"@types/promise-queue@^2.2.3":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@types/promise-queue/-/promise-queue-2.2.3.tgz#e58e17eaf855db5f6fedc47ac57f85600bf54230"
integrity sha512-CuEQpGSYKvHr3SQ7C7WkluLg9CFjVORbn8YFRsQ5u6mqGbZVfSOv03ic9t95HtZuMchnlNqnIsQGFOpxqdhjTQ==

"@types/semver@^7.5.0":
version "7.5.3"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.3.tgz#9a726e116beb26c24f1ccd6850201e1246122e04"
Expand Down Expand Up @@ -2229,6 +2224,14 @@ p-locate@^5.0.0:
dependencies:
p-limit "^3.0.2"

p-queue@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/p-queue/-/p-queue-8.0.1.tgz#718b7f83836922ef213ddec263ff4223ce70bef8"
integrity sha512-NXzu9aQJTAzbBqOt2hwsR63ea7yvxJc0PwN/zobNAudYfb1B7R08SzB4TsLeSbUCuG467NhnoT0oO6w1qRO+BA==
dependencies:
eventemitter3 "^5.0.1"
p-timeout "^6.1.2"

p-timeout@^6.1.2:
version "6.1.2"
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-6.1.2.tgz#22b8d8a78abf5e103030211c5fc6dee1166a6aa5"
Expand Down Expand Up @@ -2350,11 +2353,6 @@ prettier@^3.2.4:
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.4.tgz#4723cadeac2ce7c9227de758e5ff9b14e075f283"
integrity sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==

promise-queue@^2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/promise-queue/-/promise-queue-2.2.5.tgz#2f6f5f7c0f6d08109e967659c79b88a9ed5e93b4"
integrity sha512-p/iXrPSVfnqPft24ZdNNLECw/UrtLTpT3jpAAMzl/o5/rDsGCPo3/CQS2611flL6LkoEJ3oQZw7C8Q80ZISXRQ==

punycode@^2.1.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f"
Expand Down

0 comments on commit 30082ee

Please sign in to comment.