Skip to content

Instantly share code, notes, and snippets.

@joelbinn
joelbinn / cancellable-promise.spec.ts
Created October 8, 2019 07:03
A typescript implementation of a cancellable promise
import { CancellablePromise } from './cancellable-promise'
describe('CancellablePromise', () => {
describe('when cancelling', () => {
it( 'should reject with information of this', async () => {
const p: CancellablePromise<string> = new CancellablePromise(new Promise<string>(resolve => undefined))
p.cancel()
await expect(p).rejects.toEqual({wasCancelled: true})
@joelbinn
joelbinn / ManagerUI.java
Last active April 14, 2021 15:44
Get CDI bean from bean manager.
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.naming.InitialContext;
import javax.naming.NamingException;
:
private static BeanManager getBeanManager() {
try {
InitialContext initialContext = new InitialContext();
return (BeanManager) initialContext.lookup("java:comp/BeanManager");