feat: add async suffix eslint rule (#485)
This commit is contained in:
@@ -46,7 +46,7 @@ export const createSubPubChannel = <TData>(name: string) => {
|
||||
* Publish data to the channel with last data saved.
|
||||
* @param data data to be published
|
||||
*/
|
||||
publish: async (data: TData) => {
|
||||
publishAsync: async (data: TData) => {
|
||||
await lastDataClient.set(lastChannelName, superjson.stringify(data));
|
||||
await publisher.publish(channelName, superjson.stringify(data));
|
||||
},
|
||||
@@ -64,11 +64,11 @@ type WithId<TItem> = TItem & { _id: string };
|
||||
*/
|
||||
export const createQueueChannel = <TItem>(name: string) => {
|
||||
const queueChannelName = `queue:${name}`;
|
||||
const getData = async () => {
|
||||
const getDataAsync = async () => {
|
||||
const data = await queueClient.get(queueChannelName);
|
||||
return data ? superjson.parse<WithId<TItem>[]>(data) : [];
|
||||
};
|
||||
const setData = async (data: WithId<TItem>[]) => {
|
||||
const setDataAsync = async (data: WithId<TItem>[]) => {
|
||||
await queueClient.set(queueChannelName, superjson.stringify(data));
|
||||
};
|
||||
|
||||
@@ -77,22 +77,22 @@ export const createQueueChannel = <TItem>(name: string) => {
|
||||
* Add a new queue execution.
|
||||
* @param data data to be stored in the queue execution to run it later
|
||||
*/
|
||||
add: async (data: TItem) => {
|
||||
const items = await getData();
|
||||
addAsync: async (data: TItem) => {
|
||||
const items = await getDataAsync();
|
||||
items.push({ _id: createId(), ...data });
|
||||
await setData(items);
|
||||
await setDataAsync(items);
|
||||
},
|
||||
/**
|
||||
* Get all queue executions.
|
||||
*/
|
||||
all: getData,
|
||||
all: getDataAsync,
|
||||
/**
|
||||
* Get a queue execution by its id.
|
||||
* @param id id of the queue execution (stored under _id key)
|
||||
* @returns queue execution or undefined if not found
|
||||
*/
|
||||
byId: async (id: string) => {
|
||||
const items = await getData();
|
||||
byIdAsync: async (id: string) => {
|
||||
const items = await getDataAsync();
|
||||
return items.find((item) => item._id === id);
|
||||
},
|
||||
/**
|
||||
@@ -100,17 +100,17 @@ export const createQueueChannel = <TItem>(name: string) => {
|
||||
* @param filter callback function that returns true if the item should be included in the result
|
||||
* @returns filtered queue executions
|
||||
*/
|
||||
filter: async (filter: (item: WithId<TItem>) => boolean) => {
|
||||
const items = await getData();
|
||||
filterAsync: async (filter: (item: WithId<TItem>) => boolean) => {
|
||||
const items = await getDataAsync();
|
||||
return items.filter(filter);
|
||||
},
|
||||
/**
|
||||
* Marks an queue execution as done, by deleting it.
|
||||
* @param id id of the queue execution (stored under _id key)
|
||||
*/
|
||||
markAsDone: async (id: string) => {
|
||||
const items = await getData();
|
||||
await setData(items.filter((item) => item._id !== id));
|
||||
markAsDoneAsync: async (id: string) => {
|
||||
const items = await getDataAsync();
|
||||
await setDataAsync(items.filter((item) => item._id !== id));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user