Skip to content

Instantly share code, notes, and snippets.

@vlas-ilya
vlas-ilya / test.md
Created October 25, 2024 06:28
Задача на собеседование по flow/coroutines

В проекте есть интерфейс Paginator Джун реализовал его и заиспользовал в своей ViewMode, но проблема в том, что при запуске функции main ничего не проиходит. Помоги ему понять в чем проблема

package com.example.test  
  
import kotlinx.coroutines.CoroutineScope  
import kotlinx.coroutines.delay  
@vlas-ilya
vlas-ilya / test-java.md
Last active October 17, 2024 16:47
Задача на собеседование по синхронизации

Java вариант

Сколько будет выполняться данная программа:

public class Main {  
  
  public static void main(String... args) {  
    Test test = new Test();  
    new Thread(test::a).start();  
@vlas-ilya
vlas-ilya / SafeCoroutinesExt2.kt
Last active September 27, 2023 07:28
DSL for handling errors with launch
import kotlinx.coroutines.*
object Dispatchers {
val Main: CoroutineDispatcher get() = kotlinx.coroutines.Dispatchers.Default
val IO: CoroutineDispatcher get() = kotlinx.coroutines.Dispatchers.IO
val Default: CoroutineDispatcher get() = kotlinx.coroutines.Dispatchers.Default
val Unconfined: CoroutineDispatcher get() = kotlinx.coroutines.Dispatchers.Unconfined
}
class LaunchBlock(
@vlas-ilya
vlas-ilya / HomeScreen.kt
Last active April 20, 2022 17:08
ObserveLifecycle
package ru.test.app.ui.features.profile
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
@vlas-ilya
vlas-ilya / LoadableData.helpers.ts
Created January 3, 2022 12:57
Redux | Only one action for async process [no boilerplate code]
import { Init, LoadableData } from "./LoadableData";
import { LoadableDataEvent } from "./LoadableDataEvent";
export function init<T>(data?: T): Init<T> {
return {
state: "init",
data,
};
}
type Supplier<T> = () => T;
type Value<T> = T;
type SupplierOnValue<T> = Supplier<T> | Value<T>;
type Closable = { close(): Promise<void> };
type ClosableCreator<T> = SupplierOnValue<Promise<T>>;
type Use = <C extends Closable>(closableCreator: ClosableCreator<C>) => Promise<C>;
type Runnable<Result> = (use: Use) => Promise<Result>;
type ClosableSync = { close(): void };
@vlas-ilya
vlas-ilya / useSharedState.ts
Created July 19, 2021 18:27
React hook for sharing state between components
import { useEffect, useMemo, useRef, useState } from "react";
interface State<T> {
state: T;
setState: (state: T) => void;
handlers: ((state: T) => void) [];
}
interface GlobalState {
[key: string]: State<any>;
import { useStore } from 'effector-react'
import { useEffect } from 'react';
import { pageMounted, listStore, stateStore } from './TodoList.store';
const TodoList = () => {
useEffect(pageMounted, []);
const list = useStore(listStore);
const state = useStore(stateStore);
import { createStore, createEffect } from 'effector';
import { listApi } from '../../api/Todo';
const store = createStore({
list: [],
state: 'INIT'
});
const loadTodoList = createEffect(listApi);
import { createStore, createEffect } from 'effector';
import { listApi } from '../../api/Todo';
const listStore = createStore([]);
const stateStore = createStore('INIT');
const loadTodoList = createEffect(() => listApi());
stateStore.on(loadTodoList, () => 'LOADING');