neurosnap on main
Update effects.d.ts code docs t… (compare)
dependabot[bot] on npm_and_yarn
dependabot[bot] on npm_and_yarn
Bump http-cache-semantics from … (compare)
Hey guys, I have a more of a conceptual problem I've been struggling with in the past couple of days.
I have to subscribe to N event streams and react to the events occurring in them. Those are standard Node-like event-emitters.
I also have a facade API which should merge those N event streams together into a single one.
My initial thought was to convert the subscription into an async generator:
async function* subscribe({ fromBlock = 0, toBlock = 'latest', filter = {} } = {}) {
let res;
let rej;
let promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
const subscription = linguo.events.allEvents({ fromBlock, toBlock, filter });
subscription
.on('data', event => {
res(event);
promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
})
.on('error', err => {
rej(err);
promise = new Promise((resolve, reject) => {
res = resolve;
rej = reject;
});
});
while (true) {
try {
const event = await promise;
yield event;
} catch (err) {
console.warn(`Canceling event subscription for contract ${linguo.options.address}`, err);
break;
}
}
subscription.unsubscribe();
}
Then to combine the multiple subscribe()
calls, I've found this merge operator from the repeatable
library.
Then I happily wrote my saga:
export async function* subscribeSaga(action) {
const { fromBlock, toBlock, filter } = action.payload ?? {};
const linguoApi = yield getContext('linguoApi');
const subscription = yield call([linguoApi, 'subscribe'], { fromBlock, toBlock, filter });
for await (const evt of subscription) {
console.log('>>>', evt);
}
}
Only to find out then that redux-saga
does not support async generators :/
Any ideas?
retry
work only one time?
Hi developers
We are Ukraine based IT startup and we are looking forward to hiring 2 (two) React.js developers in a few days.
Recruitment process is simple.
If you are interested, DM me
Regards.
Andrei
Hello Everyone, MERN Stack Boilerplate provides starter kits for building web, desktop and mobile apps in pure JavaScript.
https://www.npmjs.com/package/create-mernjs-app
If you have any query or suggestions. Please let me know.
Hello Everyone,
MERN Micro Framework provides starter kits for building web, desktop and mobile apps in pure JavaScript.
https://www.npmjs.com/package/create-mernjs-app
If you have any query or suggestions. Please let me know.
function* workGetCardsFetch() {
const cards = yield call(() => axios.get('http://127.0.0.1:8000/'))
yield put(getCardsSuccess(cards.data))
}
# Post action starts here
function* workCreateCard(action) {
try {
const word = action.payload
const options = {headers: { "content-type": "application/json" }}
yield call(() => axios.post('http://127.0.0.1:8000/words/new/', { word }, options))
# I added yield workGetCardsFetch() to reload the data
# because the state in the reducer doesn't receive the new id created in the backEnd from a post request.
yield workGetCardsFetch()
} catch (error) {
console.log(error.message)
}
}
Hello Everyone
Set up a modern web, mobile & desktop app by running one command.